public MethodTable LoadType(TypeDefinition typeDef) { if (!_loadedTypes.ContainsKey(typeDef.MetadataToken)) { _loadedTypes[typeDef.MetadataToken] = MethodTableBuilder.BuildMethodTable(this, typeDef); } return _loadedTypes[typeDef.MetadataToken]; }
public void RemovePropertiesRange (TypeDefinition type) { Properties.Remove (type.token.RID); }
public bool TryGetPropertiesRange (TypeDefinition type, out Range range) { return Properties.TryGetValue (type.token.RID, out range); }
public void RemoveInterfaceMapping (TypeDefinition type) { Interfaces.Remove (type.token.RID); }
public bool TryGetInterfaceMapping (TypeDefinition type, out MetadataToken [] mapping) { return Interfaces.TryGetValue (type.token.RID, out mapping); }
public void RemoveReverseNestedTypeMapping (TypeDefinition type) { ReverseNestedTypes.Remove (type.token.RID); }
private MethodDesc[] CreateMethodSlotsFromTypeDef(TypeDefinition typeDef) { var methods = new List<MethodDefinition>(); methods.AddRange(GetVirtualMethodDefsFromTypeDef(typeDef)); // virtual methods.AddRange(typeDef.Methods.Where(x => !x.IsVirtual && !x.IsStatic)); // non-virtual methods.AddRange(typeDef.Methods.Where(x => x.IsStatic)); // static return methods .Select((x, i) => { var methodDesc = _classLoader.LookupMethodDescFromMethodDef(x); if (methodDesc == null) { methodDesc = new MethodDesc() { MdToken = x.MetadataToken, Name = x.FullName, Definition = x, Slot = i }; _classLoader.RegisterMethodDesc(x, methodDesc); } return methodDesc; }) .ToArray(); }
static TypeDefinition BinaryRangeSearch (TypeDefinition [] types, uint rid, bool field) { int min = 0; int max = types.Length - 1; while (min <= max) { int mid = min + ((max - min) / 2); var type = types [mid]; var range = field ? type.fields_range : type.methods_range; if (rid < range.Start) max = mid - 1; else if (rid >= range.Start + range.Length) min = mid + 1; else return type; } return null; }
public void AddTypeDefinition (TypeDefinition type) { Types [type.token.RID - 1] = type; }
public static bool TryGetPrimitiveElementType (TypeDefinition type, out ElementType etype) { etype = ElementType.None; if (type.Namespace != "System") return false; Row<ElementType, bool> primitive_data; if (TryGetPrimitiveData (type, out primitive_data) && primitive_data.Col1.IsPrimitive ()) { etype = primitive_data.Col1; return true; } return false; }
MethodDefinition GetMethod (TypeDefinition type, MethodReference reference) { while (type != null) { var method = GetMethod (type.Methods, reference); if (method != null) return method; if (type.BaseType == null) return null; type = Resolve (type.BaseType); } return null; }
FieldDefinition GetField (TypeDefinition type, FieldReference reference) { while (type != null) { var field = GetField (type.Fields, reference); if (field != null) return field; if (type.BaseType == null) return null; type = Resolve (type.BaseType); } return null; }
public static MethodTable BuildMethodTable(ClassLoader classLoader, TypeDefinition typeDef) { return new MethodTableBuilder(classLoader, typeDef).BuildMethodTable(); }
public MethodTableBuilder(ClassLoader classLoader, TypeDefinition typeDef) { _classLoader = classLoader; _typeDefinition = typeDef; }
public bool TryGetEventsRange (TypeDefinition type, out Range range) { return Events.TryGetValue (type.token.RID, out range); }
public void RemoveEventsRange (TypeDefinition type) { Events.Remove (type.token.RID); }
public bool TryGetNestedTypeMapping (TypeDefinition type, out uint [] mapping) { return NestedTypes.TryGetValue (type.token.RID, out mapping); }
public bool TryGetReverseNestedTypeMapping (TypeDefinition type, out uint declaring) { return ReverseNestedTypes.TryGetValue (type.token.RID, out declaring); }
private MethodDefinition[] GetVirtualMethodDefsFromTypeDef(TypeDefinition typeDef) { var methods = new List<MethodDefinition>(); var declaredMethods = typeDef.Methods.Where(x => x.IsVirtual && !x.IsStatic && !x.DeclaringType.IsInterface).ToArray(); var nonOverrideMethods = new List<MethodDefinition>(); if (typeDef.BaseType != null) { var parentMethods = GetVirtualMethodDefsFromTypeDef(typeDef.BaseType.Resolve()); for (var i = 0; i < declaredMethods.Length; i++) { var declMethod = declaredMethods[i]; var overrided = false; for (var j = 0; j < parentMethods.Length; j++) { var parentMethod = parentMethods[j]; if (parentMethod.Name == declMethod.Name /* && ... */) { parentMethods[j] = declMethod; overrided = true; break; } } if (!overrided) { nonOverrideMethods.Add(declMethod); } } methods.AddRange(parentMethods); // virtual (parent/override) methods.AddRange(nonOverrideMethods); // virtual } else { methods.AddRange(declaredMethods); // virtual } return methods.ToArray(); }