Don't enumerate fields on generic type Def (#77)

* Don't enumerate fields on generic type Def

Prevent exception being thrown when generic type definition is not a constructed generic type when trying to retrieve field values.

Added TODO with suggestion as to how to diagnose type arguments for generic type definition to create a constructed generic type.

* add test demonstrating error
This commit is contained in:
Tyler Young
2018-11-11 19:10:22 -05:00
committed by Ben Adams
parent c3519f14c5
commit aa10921687
2 changed files with 59 additions and 10 deletions

View File

@@ -136,19 +136,26 @@ namespace System.Diagnostics
{
if (methodName == ".cctor")
{
var fields = type.GetFields(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
foreach (var field in fields)
if (type.IsGenericTypeDefinition && !type.IsConstructedGenericType)
{
var value = field.GetValue(field);
if (value is Delegate d)
// TODO: diagnose type's generic type arguments from frame's "this" or something
}
else
{
var fields = type.GetFields(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
foreach (var field in fields)
{
if (ReferenceEquals(d.Method, originMethod) &&
d.Target.ToString() == originMethod.DeclaringType.ToString())
var value = field.GetValue(field);
if (value is Delegate d)
{
methodDisplayInfo.Name = field.Name;
methodDisplayInfo.IsLambda = false;
method = originMethod;
break;
if (ReferenceEquals(d.Method, originMethod) &&
d.Target.ToString() == originMethod.DeclaringType.ToString())
{
methodDisplayInfo.Name = field.Name;
methodDisplayInfo.IsLambda = false;
method = originMethod;
break;
}
}
}
}