Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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;
        }
Exemplo n.º 3
0
        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);
        }