public static bool IsImplementationOf(TypeDefinition thisTypeDefinition, TypeDefinition interfaceTypeDefinition, IEmitter emitter) { foreach (TypeReference interfaceReference in thisTypeDefinition.Interfaces) { var iref = interfaceReference; if (interfaceReference.IsGenericInstance) { iref = interfaceReference.GetElementType(); } if (iref == interfaceTypeDefinition) { return true; } TypeDefinition interfaceDefinition = null; try { interfaceDefinition = Helpers.ToTypeDefinition(iref, emitter); } catch { } if (interfaceDefinition != null && Helpers.IsImplementationOf(interfaceDefinition, interfaceTypeDefinition, emitter)) { return true; } } return false; }
public static bool IsTypeArgInSubclass(TypeDefinition thisTypeDefinition, TypeDefinition typeArgDefinition, IEmitter emitter, bool deep = true) { foreach (TypeReference interfaceReference in thisTypeDefinition.Interfaces) { var gBaseType = interfaceReference as GenericInstanceType; if (gBaseType != null && Helpers.HasGenericArgument(gBaseType, typeArgDefinition, emitter)) { return(true); } } if (thisTypeDefinition.BaseType != null) { TypeDefinition baseTypeDefinition = null; var gBaseType = thisTypeDefinition.BaseType as GenericInstanceType; if (gBaseType != null && Helpers.HasGenericArgument(gBaseType, typeArgDefinition, emitter)) { return(true); } try { baseTypeDefinition = Helpers.ToTypeDefinition(thisTypeDefinition.BaseType, emitter); } catch { } if (baseTypeDefinition != null && deep) { return(Helpers.IsTypeArgInSubclass(baseTypeDefinition, typeArgDefinition, emitter)); } } return(false); }
public static TypeDefinition GetBaseType(TypeDefinition type, IEmitter emitter) { if (type == null || type.BaseType == null) { return(null); } return(Helpers.ToTypeDefinition(type.BaseType, emitter)); }
public static bool HasGenericArgument(GenericInstanceType type, TypeDefinition searchType, IEmitter emitter, bool deep) { foreach (var gArg in type.GenericArguments) { var orig = gArg; var gArgDef = gArg; if (gArgDef.IsGenericInstance) { gArgDef = gArgDef.GetElementType(); } TypeDefinition gTypeDef = null; try { gTypeDef = Helpers.ToTypeDefinition(gArgDef, emitter); } catch { } if (gTypeDef == searchType) { return true; } if (deep && gTypeDef != null && (Helpers.IsSubclassOf(gTypeDef, searchType, emitter) || (searchType.IsInterface && Helpers.IsImplementationOf(gTypeDef, searchType, emitter)))) { return true; } if (orig.IsGenericInstance) { var result = Helpers.HasGenericArgument((GenericInstanceType)orig, searchType, emitter, deep); if (result) { return true; } } } return false; }
public static bool IsSubclassOf(TypeDefinition thisTypeDefinition, TypeDefinition typeDefinition, IEmitter emitter) { if (thisTypeDefinition.BaseType != null) { TypeDefinition baseTypeDefinition = null; try { baseTypeDefinition = Helpers.ToTypeDefinition(thisTypeDefinition.BaseType, emitter); } catch { } if (baseTypeDefinition != null) { return(baseTypeDefinition == typeDefinition || Helpers.IsSubclassOf(baseTypeDefinition, typeDefinition, emitter)); } } return(false); }
public static List<MethodDefinition> GetMethods(TypeDefinition typeDef, IEmitter emitter, List<MethodDefinition> list = null) { if (list == null) { list = new List<MethodDefinition>(typeDef.Methods); } else { list.AddRange(typeDef.Methods); } var baseTypeDefinition = Helpers.ToTypeDefinition(typeDef.BaseType, emitter); if (baseTypeDefinition != null) { Helpers.GetMethods(baseTypeDefinition, emitter, list); } return list; }
public static bool HasGenericArgument(GenericInstanceType type, TypeDefinition searchType, IEmitter emitter) { foreach (var gArg in type.GenericArguments) { var orig = gArg; var gArgDef = gArg; if (gArgDef.IsGenericInstance) { gArgDef = gArgDef.GetElementType(); } TypeDefinition gTypeDef = null; try { gTypeDef = Helpers.ToTypeDefinition(gArgDef, emitter); } catch { } if (gTypeDef == searchType) { return(true); } if (orig.IsGenericInstance) { var result = Helpers.HasGenericArgument((GenericInstanceType)orig, searchType, emitter); if (result) { return(true); } } } return(false); }
public static bool IsImplementationOf(TypeDefinition thisTypeDefinition, TypeDefinition interfaceTypeDefinition, IEmitter emitter) { foreach (TypeReference interfaceReference in thisTypeDefinition.Interfaces) { if (interfaceReference == interfaceTypeDefinition) { return(true); } TypeDefinition interfaceDefinition = null; try { interfaceDefinition = Helpers.ToTypeDefinition(interfaceReference, emitter); } catch { } if (interfaceDefinition != null && Helpers.IsImplementationOf(interfaceDefinition, interfaceTypeDefinition, emitter)) { return(true); } } return(false); }