示例#1
0
        private static TypeReference InflateGenericType(GenericInstanceType genericInstanceProvider, TypeReference typeToInflate)
        {
            ArrayType type = typeToInflate as ArrayType;

            if (type != null)
            {
                TypeReference reference = InflateGenericType(genericInstanceProvider, type.ElementType);
                if (reference != type.ElementType)
                {
                    return(new ArrayType(reference, type.Rank));
                }
                return(type);
            }
            GenericInstanceType baseType = typeToInflate as GenericInstanceType;

            if (baseType != null)
            {
                return(MakeGenericType(genericInstanceProvider, baseType));
            }
            GenericParameter genericParameter = typeToInflate as GenericParameter;

            if (genericParameter != null)
            {
                GenericParameter parameter = ResolveType(genericInstanceProvider.ElementType).GenericParameters.Single <GenericParameter>(p => p == genericParameter);
                return(genericInstanceProvider.GenericArguments[parameter.Position]);
            }
            FunctionPointerType type3 = typeToInflate as FunctionPointerType;

            if (type3 != null)
            {
                FunctionPointerType type9 = new FunctionPointerType {
                    ReturnType = InflateGenericType(genericInstanceProvider, type3.ReturnType)
                };
                for (int i = 0; i < type3.Parameters.Count; i++)
                {
                    TypeReference parameterType = InflateGenericType(genericInstanceProvider, type3.Parameters[i].ParameterType);
                    type9.Parameters.Add(new ParameterDefinition(parameterType));
                }
                return(type9);
            }
            IModifierType type4 = typeToInflate as IModifierType;

            if (type4 != null)
            {
                TypeReference modifierType = InflateGenericType(genericInstanceProvider, type4.ModifierType);
                TypeReference reference4   = InflateGenericType(genericInstanceProvider, type4.ElementType);
                if (type4 is OptionalModifierType)
                {
                    return(new OptionalModifierType(modifierType, reference4));
                }
                return(new RequiredModifierType(modifierType, reference4));
            }
            PinnedType type5 = typeToInflate as PinnedType;

            if (type5 != null)
            {
                TypeReference reference5 = InflateGenericType(genericInstanceProvider, type5.ElementType);
                if (reference5 != type5.ElementType)
                {
                    return(new PinnedType(reference5));
                }
                return(type5);
            }
            PointerType type6 = typeToInflate as PointerType;

            if (type6 != null)
            {
                TypeReference reference6 = InflateGenericType(genericInstanceProvider, type6.ElementType);
                if (reference6 != type6.ElementType)
                {
                    return(new PointerType(reference6));
                }
                return(type6);
            }
            ByReferenceType type7 = typeToInflate as ByReferenceType;

            if (type7 != null)
            {
                TypeReference reference7 = InflateGenericType(genericInstanceProvider, type7.ElementType);
                if (reference7 != type7.ElementType)
                {
                    return(new ByReferenceType(reference7));
                }
                return(type7);
            }
            SentinelType type8 = typeToInflate as SentinelType;

            if (type8 == null)
            {
                return(typeToInflate);
            }
            TypeReference reference8 = InflateGenericType(genericInstanceProvider, type8.ElementType);

            if (reference8 != type8.ElementType)
            {
                return(new SentinelType(reference8));
            }
            return(type8);
        }
示例#2
0
        public TypeReference Retarget(TypeReference type, GenericContext context)
        {
            TypeReference reference;

            if (type == null)
            {
                return(type);
            }
            if ((type.IsFunctionPointer || type.IsOptionalModifier) || type.IsSentinel)
            {
                throw new NotImplementedException();
            }
            if (type.IsArray)
            {
                ArrayType type2 = (ArrayType)type;
                ArrayType type3 = new ArrayType(this.Retarget(type2.ElementType, context), type2.Rank);
                for (int i = 0; i < type2.Dimensions.Count; i++)
                {
                    ArrayDimension dimension = type2.Dimensions[i];
                    type3.Dimensions[i] = new ArrayDimension(dimension.LowerBound, dimension.UpperBound);
                }
                reference = type3;
            }
            else if (type.IsByReference)
            {
                ByReferenceType type4 = (ByReferenceType)type;
                reference = new ByReferenceType(this.Retarget(type4.ElementType, context));
            }
            else if (type.IsDefinition && Utility.SameScope(type.Scope, this.Module))
            {
                reference = type;
            }
            else if (type.IsGenericInstance)
            {
                GenericInstanceType type5 = (GenericInstanceType)type;
                GenericInstanceType type6 = new GenericInstanceType(this.Retarget(type5.ElementType, context));
                foreach (TypeReference reference2 in type5.GenericArguments)
                {
                    TypeReference item = this.Retarget(reference2, context);
                    type6.GenericArguments.Add(item);
                }
                reference = type6;
            }
            else
            {
                if (type.IsGenericParameter)
                {
                    GenericParameter parameter = (GenericParameter)type;
                    return(context.Retarget(parameter));
                }
                if (type.IsPinned)
                {
                    PinnedType type7 = (PinnedType)type;
                    reference = new PinnedType(this.Retarget(type7.ElementType, context));
                }
                else if (type.IsPointer)
                {
                    PointerType type8 = (PointerType)type;
                    reference = new PointerType(this.Retarget(type8.ElementType, context));
                }
                else if (type.IsRequiredModifier)
                {
                    RequiredModifierType type9 = (RequiredModifierType)type;
                    reference = new RequiredModifierType(this.Retarget(type9.ModifierType, context), this.Retarget(type9.ElementType, context));
                }
                else
                {
                    reference = type.Resolve();
                    if ((reference == null) && (this.OperationContext.Platform == Platform.UAP))
                    {
                        string fullName = null;
                        string str2     = type.FullName;
                        if ((!(str2 == "System.Collections.ArrayList") && !(str2 == "System.Collections.CollectionBase")) && (!(str2 == "System.Collections.Hashtable") && !(str2 == "System.Collections.Stack")))
                        {
                            if (str2 == "System.Reflection.BindingFlags")
                            {
                                fullName = "System.Reflection.TypeExtensions";
                            }
                        }
                        else
                        {
                            fullName = "System.Collections.NonGeneric";
                        }
                        if (fullName != null)
                        {
                            IMetadataScope scope = type.Scope;
                            type.Scope = AssemblyNameReference.Parse(fullName);
                            reference  = type.Resolve();
                            type.Scope = scope;
                        }
                    }
                }
            }
            return(this.Module.ImportReference(reference));
        }