Exemplo n.º 1
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));
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        public static bool MatchInterfaceMethod(MethodDef?candidate, MethodDef?method, ITypeDefOrRef interfaceContextType)
        {
            var genericInstSig = interfaceContextType.TryGetGenericInstSig();

            if (!(genericInstSig is null))
            {
                return(MatchMethod(candidate, candidate?.MethodSig, method, GenericArgumentResolver.Resolve(method?.MethodSig, genericInstSig.GenericArguments, null)));
            }
Exemplo n.º 4
0
        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));
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Resolves the method signature with the specified generic arguments.
        /// </summary>
        /// <param name="methodSig">The method signature.</param>
        /// <param name="typeGenArgs">The type generic arguments.</param>
        /// <param name="methodGenArgs">The method generic arguments.</param>
        /// <returns>Resolved method signature.</returns>
        /// <exception cref="System.ArgumentException">No generic arguments to resolve.</exception>
        public static MethodBaseSig?Resolve(MethodBaseSig?methodSig, IList <TypeSig>?typeGenArgs, IList <TypeSig>?methodGenArgs)
        {
            if (methodSig is null)
            {
                return(null);
            }
            if ((typeGenArgs is null || typeGenArgs.Count == 0) && (methodGenArgs is null || methodGenArgs.Count == 0))
            {
                return(methodSig);
            }

            var resolver = new GenericArgumentResolver(typeGenArgs, methodGenArgs);

            return(resolver.ResolveGenericArgs(methodSig));
        }
Exemplo n.º 6
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 || typeGenArgs.Count == 0) && (methodGenArgs == null || methodGenArgs.Count == 0))
            {
                return(typeSig);
            }

            var resolver = new GenericArgumentResolver(typeGenArgs, methodGenArgs);

            return(resolver.ResolveGenericArgs(typeSig));
        }
Exemplo n.º 7
0
        private static MethodSig Resolve(MethodBaseSig method, TypeSig typeContext)
        {
            var genericArgs = typeContext is GenericInstSig ? ((GenericInstSig)typeContext).GenericArguments : null;

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

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