mirror of
https://github.com/github/codeql.git
synced 2026-04-28 02:05:14 +02:00
Merge pull request #4970 from tamasvajk/feature/extraction-errors
C#: Fix extraction errors
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection.Metadata;
|
||||
|
||||
namespace Semmle.Extraction.CIL.Entities
|
||||
@@ -36,12 +37,26 @@ namespace Semmle.Extraction.CIL.Entities
|
||||
}
|
||||
|
||||
var name = type.GetQualifiedName();
|
||||
|
||||
if (wellKnownEnums.TryGetValue(name, out var code))
|
||||
{
|
||||
cx.Cx.Extractor.Logger.Log(Util.Logging.Severity.Debug, $"Using hard coded underlying enum type for {name}");
|
||||
return code;
|
||||
}
|
||||
|
||||
cx.Cx.Extractor.Logger.Log(Util.Logging.Severity.Info, $"Couldn't get underlying enum type for {name}");
|
||||
|
||||
// We can't fall back to Int32, because the type returned here defines how many bytes are read from the
|
||||
// stream and how those bytes are interpreted.
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public bool IsSystemType(Type type) => type.GetQualifiedName() == "System.Type";
|
||||
|
||||
private static readonly Dictionary<string, PrimitiveTypeCode> wellKnownEnums = new Dictionary<string, PrimitiveTypeCode>
|
||||
{
|
||||
{ "System.AttributeTargets", PrimitiveTypeCode.Int32 },
|
||||
{ "System.ComponentModel.EditorBrowsableState", PrimitiveTypeCode.Int32 }
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Semmle.Util;
|
||||
|
||||
namespace Semmle.Extraction.CIL.Entities
|
||||
{
|
||||
@@ -21,6 +20,7 @@ namespace Semmle.Extraction.CIL.Entities
|
||||
private readonly Type[]? thisTypeArguments;
|
||||
private readonly Type unboundGenericType;
|
||||
private readonly Type? containingType;
|
||||
private readonly Namespace? containingNamespace;
|
||||
|
||||
private readonly NamedTypeIdWriter idWriter;
|
||||
|
||||
@@ -53,13 +53,20 @@ namespace Semmle.Extraction.CIL.Entities
|
||||
? null
|
||||
: new NoMetadataHandleType(Cx, containerName);
|
||||
|
||||
containingNamespace = isContainerNamespace
|
||||
? containerName == Cx.GlobalNamespace.Name
|
||||
? Cx.GlobalNamespace
|
||||
: containerName == Cx.SystemNamespace.Name
|
||||
? Cx.SystemNamespace
|
||||
: new Namespace(Cx, containerName)
|
||||
: null;
|
||||
|
||||
Populate();
|
||||
}
|
||||
|
||||
private void Populate()
|
||||
{
|
||||
if (isContainerNamespace &&
|
||||
!ContainingNamespace!.IsGlobalNamespace)
|
||||
if (isContainerNamespace)
|
||||
{
|
||||
Cx.Populate(ContainingNamespace);
|
||||
}
|
||||
@@ -100,11 +107,7 @@ namespace Semmle.Extraction.CIL.Entities
|
||||
|
||||
public override string Name => GenericsHelper.GetNonGenericName(name);
|
||||
|
||||
public override Namespace? ContainingNamespace => isContainerNamespace
|
||||
? containerName == Cx.GlobalNamespace.Name
|
||||
? Cx.GlobalNamespace
|
||||
: new Namespace(Cx, containerName)
|
||||
: null;
|
||||
public override Namespace? ContainingNamespace => containingNamespace;
|
||||
|
||||
public override Type? ContainingType => containingType;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user