mirror of
https://github.com/github/codeql.git
synced 2026-04-24 16:25:15 +02:00
Add method to get qualified name of CIL extraction types
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection.Metadata;
|
||||
using System.Reflection.PortableExecutable;
|
||||
|
||||
@@ -83,7 +82,7 @@ namespace Semmle.Extraction.CIL
|
||||
trapFile.Write(GetString(def.Name));
|
||||
trapFile.Write('_');
|
||||
trapFile.Write(def.Version.ToString());
|
||||
trapFile.Write("::");
|
||||
trapFile.Write(Entities.Type.AssemblyTypeNameSeparator);
|
||||
}
|
||||
|
||||
public Entities.TypeSignatureDecoder TypeSignatureDecoder { get; }
|
||||
|
||||
@@ -12,7 +12,8 @@ namespace Semmle.Extraction.CIL.Entities
|
||||
public abstract class Type : TypeContainer, IMember
|
||||
{
|
||||
public override string IdSuffix => ";cil-type";
|
||||
internal const string PrimitiveTypePrefix = "builtin:";
|
||||
internal const string AssemblyTypeNameSeparator = "::";
|
||||
internal const string PrimitiveTypePrefix = "builtin" + AssemblyTypeNameSeparator + "System.";
|
||||
|
||||
protected Type(Context cx) : base(cx) { }
|
||||
|
||||
@@ -72,6 +73,21 @@ namespace Semmle.Extraction.CIL.Entities
|
||||
|
||||
public void GetId(TextWriter trapFile, bool inContext) => WriteId(trapFile, inContext);
|
||||
|
||||
/// <summary>
|
||||
/// Returns the friendly qualified name of types, such as
|
||||
/// ``"System.Collection.Generic.List`1"`` or
|
||||
/// ``"System.Collection.Generic.List<System.Int32>"``.
|
||||
///
|
||||
/// Note that method/type generic type parameters never show up in the returned name.
|
||||
/// </summary>
|
||||
public string GetQualifiedName()
|
||||
{
|
||||
using var writer = new StringWriter();
|
||||
GetId(writer, false);
|
||||
var name = writer.ToString();
|
||||
return name.Substring(name.IndexOf(AssemblyTypeNameSeparator) + 2);
|
||||
}
|
||||
|
||||
public abstract CilTypeKind Kind { get; }
|
||||
|
||||
public override IEnumerable<IExtractionProduct> Contents
|
||||
|
||||
@@ -114,7 +114,7 @@ namespace Semmle.Extraction.CIL.Entities
|
||||
trapFile.Write(Cx.GetString(assemblyDef.Name));
|
||||
trapFile.Write('_');
|
||||
trapFile.Write(assemblyDef.Version.ToString());
|
||||
trapFile.Write("::");
|
||||
trapFile.Write(Entities.Type.AssemblyTypeNameSeparator);
|
||||
break;
|
||||
default:
|
||||
Cx.WriteAssemblyPrefix(trapFile);
|
||||
|
||||
Reference in New Issue
Block a user