private static IEnumerable <TypeSig> BaseTypes(TypeDef typeDef)
        {
            if (typeDef == null)
            {
                yield break;
            }
            if (typeDef.BaseType == null)
            {
                yield break;
            }

            TypeSig baseType = typeDef.ToTypeSig();

            do
            {
                var genericArgs = baseType is GenericInstSig ? ((GenericInstSig)baseType).GenericArguments : null;
                baseType = GenericArgumentResolver.Resolve(typeDef.BaseType.ToTypeSig(), genericArgs, null);
                yield return(baseType);

                typeDef = typeDef.BaseType.ResolveTypeDef();
                if (typeDef == null)
                {
                    break;
                }
            } while (typeDef.BaseType != null);
        }
示例#2
0
        /// <summary>
        /// Resolves the type signature with the specified generic arguments.
        /// </summary>
        /// <param name="typeSig">The type signature.</param>
        /// <param name="typeGenArgs">The type generic arguments.</param>
        /// <param name="methodGenArgs">The method generic arguments.</param>
        /// <returns>Resolved type signature.</returns>
        /// <exception cref="System.ArgumentException">No generic arguments to resolve.</exception>
        public static TypeSig Resolve(TypeSig typeSig, IList <TypeSig> typeGenArgs, IList <TypeSig> methodGenArgs)
        {
            if (typeSig == null)
            {
                return(typeSig);
            }
            if (typeGenArgs == null && methodGenArgs == null)
            {
                return(typeSig);
            }

            var resolver = new GenericArgumentResolver();

            resolver.genericArguments = new GenericArguments();
            resolver.recursionCounter = new RecursionCounter();

            if (typeGenArgs != null)
            {
                resolver.genericArguments.PushTypeArgs(typeGenArgs);
            }

            if (methodGenArgs != null)
            {
                resolver.genericArguments.PushMethodArgs(methodGenArgs);
            }

            return(resolver.ResolveGenericArgs(typeSig));
        }
        public static bool MatchInterfaceMethod(MethodDef candidate, MethodDef method, ITypeDefOrRef interfaceContextType)
        {
            var genericInstSig = interfaceContextType.TryGetGenericInstSig();

            if (genericInstSig != null)
            {
                return(MatchMethod(candidate, GenericArgumentResolver.Resolve(candidate == null ? null : candidate.MethodSig, genericInstSig.GenericArguments, null), method));
            }
            else
            {
                return(MatchMethod(candidate, candidate == null ? null : candidate.MethodSig, method));
            }
        }
        private static MethodSig Resolve(MethodBaseSig method, TypeSig typeContext)
        {
            var genericArgs = typeContext is GenericInstSig ? ((GenericInstSig)typeContext).GenericArguments : null;

            return(GenericArgumentResolver.Resolve(method, genericArgs, null));
        }
        private static TypeSig Resolve(TypeSig type, TypeSig typeContext)
        {
            var genericArgs = typeContext is GenericInstSig ? ((GenericInstSig)typeContext).GenericArguments : null;

            return(GenericArgumentResolver.Resolve(type, genericArgs, null));
        }