Add events, fields and properties to concrete generics.

This basically finishes the concrete generics implementation. We can now
enumerate all members of a concrete generic type with full type
substitution implemented.

Also add a simple test to verify that we can obtain the correct type for
a field of a concrete generic type.
This commit is contained in:
Robert Xiao
2020-04-13 06:45:04 -07:00
committed by Katy
parent 1a12567227
commit 4207464208
5 changed files with 98 additions and 15 deletions

View File

@@ -15,12 +15,14 @@ namespace Il2CppInspector.Reflection
// IL2CPP-specific data
public Il2CppEventDefinition Definition { get; }
public int Index { get; }
// Root definition: the event with Definition != null
protected readonly EventInfo rootDefinition;
// Information/flags about the event
public EventAttributes Attributes { get; }
// Custom attributes for this member
public override IEnumerable<CustomAttributeData> CustomAttributes => CustomAttributeData.GetCustomAttributes(this);
public override IEnumerable<CustomAttributeData> CustomAttributes => CustomAttributeData.GetCustomAttributes(rootDefinition);
// Methods for the event
public MethodInfo AddMethod { get; }
@@ -41,6 +43,7 @@ namespace Il2CppInspector.Reflection
Definition = pkg.Events[eventIndex];
Index = eventIndex;
Name = pkg.Strings[Definition.nameIndex];
rootDefinition = this;
eventTypeReference = TypeRef.FromReferenceIndex(Assembly.Model, Definition.typeIndex);
var eventType = pkg.TypeReferences[Definition.typeIndex];
@@ -57,5 +60,17 @@ namespace Il2CppInspector.Reflection
if (Definition.raise >= 0)
RaiseMethod = declaringType.DeclaredMethods.First(x => x.Index == declaringType.Definition.methodStart + Definition.raise);
}
public EventInfo(EventInfo eventDef, TypeInfo declaringType) : base(declaringType) {
rootDefinition = eventDef;
Name = eventDef.Name;
Attributes = eventDef.Attributes;
eventTypeReference = TypeRef.FromTypeInfo(eventDef.EventHandlerType.SubstituteGenericArguments(declaringType.GetGenericArguments()));
AddMethod = declaringType.GetMethodByDefinition(eventDef.AddMethod);
RemoveMethod = declaringType.GetMethodByDefinition(eventDef.RemoveMethod);
RaiseMethod = declaringType.GetMethodByDefinition(eventDef.RaiseMethod);
}
}
}