mirror of
https://github.com/github/codeql.git
synced 2026-04-24 00:05:14 +02:00
C#: Even more reflection for retrieving meta data handle
This commit is contained in:
@@ -136,16 +136,32 @@ namespace Semmle.Extraction.CSharp.Entities
|
||||
trapFile.metadata_handle(this, Location, MetadataTokens.GetToken(handle.Value));
|
||||
}
|
||||
|
||||
static System.Reflection.PropertyInfo GetPropertyInfo(object o, string name) =>
|
||||
o.GetType().GetProperty(name, System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.GetProperty);
|
||||
|
||||
public Handle? MetadataHandle
|
||||
{
|
||||
get
|
||||
{
|
||||
var propertyInfo = symbol.GetType().GetProperty("Handle",
|
||||
System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.GetProperty);
|
||||
var handleProp = GetPropertyInfo(symbol, "Handle");
|
||||
object handleObj = symbol;
|
||||
|
||||
if (propertyInfo != null)
|
||||
if (handleProp is null)
|
||||
{
|
||||
switch (propertyInfo.GetValue(symbol))
|
||||
var underlyingSymbolProp = GetPropertyInfo(symbol, "UnderlyingSymbol");
|
||||
if (underlyingSymbolProp is object)
|
||||
{
|
||||
if (underlyingSymbolProp.GetValue(symbol) is object underlying)
|
||||
{
|
||||
handleProp = GetPropertyInfo(underlying, "Handle");
|
||||
handleObj = underlying;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (handleProp is object)
|
||||
{
|
||||
switch (handleProp.GetValue(handleObj))
|
||||
{
|
||||
case MethodDefinitionHandle md: return md;
|
||||
case TypeDefinitionHandle td: return td;
|
||||
|
||||
Reference in New Issue
Block a user