예제 #1
0
        public static TypeReference SubstituteTypeArgs(ITypeInfoSource typeInfo, TypeReference type, MemberReference member)
        {
            var gp = (type as GenericParameter);

            if (gp != null)
            {
                if (gp.Owner.GenericParameterType == GenericParameterType.Method)
                {
                    var ownerIdentifier  = new MemberIdentifier(typeInfo, (MethodReference)gp.Owner);
                    var memberIdentifier = new MemberIdentifier(typeInfo, (dynamic)member);

                    if (!ownerIdentifier.Equals(memberIdentifier, typeInfo))
                    {
                        return(type);
                    }

                    if (!(member is GenericInstanceMethod))
                    {
                        return(type);
                    }
                }
                else
                {
                    var declaringType = member.DeclaringType.Resolve();
                    // FIXME: Is this right?
                    if (declaringType == null)
                    {
                        return(type);
                    }

                    var ownerResolved = ((TypeReference)gp.Owner).Resolve();
                    // FIXME: Is this right?
                    if (ownerResolved == null)
                    {
                        return(type);
                    }

                    var ownerIdentifier = new TypeIdentifier(ownerResolved);
                    var typeIdentifier  = new TypeIdentifier(declaringType);

                    if (!ownerIdentifier.Equals(typeIdentifier))
                    {
                        return(type);
                    }
                }
            }

            return(TypeAnalysis.SubstituteTypeArgs(type, member));
        }
예제 #2
0
        public static TypeReference SubstituteTypeArgs(ITypeInfoSource typeInfo, TypeReference type, MemberReference member)
        {
            var gp = (type as GenericParameter);

            if (gp != null)
            {
                if (gp.Owner.GenericParameterType == GenericParameterType.Method)
                {
                    var ownerIdentifier  = new MemberIdentifier(typeInfo, gp.Owner as MethodReference);
                    var memberIdentifier = new MemberIdentifier(typeInfo, member as dynamic);

                    if (!ownerIdentifier.Equals(memberIdentifier, typeInfo))
                    {
                        return(type);
                    }

                    if (!(member is GenericInstanceMethod))
                    {
                        return(type);
                    }
                }
                else
                {
                    var declaringType   = member.DeclaringType;
                    var ownerIdentifier = new TypeIdentifier(gp.Owner as TypeReference);
                    var typeIdentifier  = new TypeIdentifier(declaringType);

                    if (!ownerIdentifier.Equals(typeIdentifier))
                    {
                        return(type);
                    }
                }
            }

            return(TypeAnalysis.SubstituteTypeArgs(type, member));
        }