示例#1
0
        private static TypeReference CreateSpecs(TypeReference type, TypeParser.Type type_info)
        {
            type = TypeParser.TryCreateGenericInstanceType(type, type_info);
            int[] specs = type_info.specs;
            if (specs.IsNullOrEmpty <int>())
            {
                return(type);
            }
            for (int i = 0; i < specs.Length; i++)
            {
                switch (specs[i])
                {
                case -3:
                    type = new ArrayType(type);
                    break;

                case -2:
                    type = new ByReferenceType(type);
                    break;

                case -1:
                    type = new PointerType(type);
                    break;

                default:
                {
                    ArrayType arrayType = new ArrayType(type);
                    arrayType.Dimensions.Clear();
                    for (int j = 0; j < specs[i]; j++)
                    {
                        arrayType.Dimensions.Add(default(ArrayDimension));
                    }
                    type = arrayType;
                    break;
                }
                }
            }
            return(type);
        }
示例#2
0
        private TypeReference ImportTypeSpecification(TypeReference type, ImportGenericContext context)
        {
            ElementType etype = type.etype;

            switch (etype)
            {
            case ElementType.Ptr:
            {
                PointerType pointerType = (PointerType)type;
                return(new PointerType(this.ImportType(pointerType.ElementType, context)));
            }

            case ElementType.ByRef:
            {
                ByReferenceType byReferenceType = (ByReferenceType)type;
                return(new ByReferenceType(this.ImportType(byReferenceType.ElementType, context)));
            }

            case ElementType.ValueType:
            case ElementType.Class:
            case ElementType.TypedByRef:
            case (ElementType)23:
            case ElementType.I:
            case ElementType.U:
            case (ElementType)26:
            case ElementType.Object:
                break;

            case ElementType.Var:
            {
                GenericParameter genericParameter = (GenericParameter)type;
                if (genericParameter.DeclaringType == null)
                {
                    throw new InvalidOperationException();
                }
                return(context.TypeParameter(genericParameter.DeclaringType.FullName, genericParameter.Position));
            }

            case ElementType.Array:
            {
                ArrayType arrayType  = (ArrayType)type;
                ArrayType arrayType2 = new ArrayType(this.ImportType(arrayType.ElementType, context));
                if (arrayType.IsVector)
                {
                    return(arrayType2);
                }
                Collection <ArrayDimension> dimensions  = arrayType.Dimensions;
                Collection <ArrayDimension> dimensions2 = arrayType2.Dimensions;
                dimensions2.Clear();
                for (int i = 0; i < dimensions.Count; i++)
                {
                    ArrayDimension arrayDimension = dimensions[i];
                    dimensions2.Add(new ArrayDimension(arrayDimension.LowerBound, arrayDimension.UpperBound));
                }
                return(arrayType2);
            }

            case ElementType.GenericInst:
            {
                GenericInstanceType        genericInstanceType = (GenericInstanceType)type;
                TypeReference              type2 = this.ImportType(genericInstanceType.ElementType, context);
                GenericInstanceType        genericInstanceType2 = new GenericInstanceType(type2);
                Collection <TypeReference> genericArguments     = genericInstanceType.GenericArguments;
                Collection <TypeReference> genericArguments2    = genericInstanceType2.GenericArguments;
                for (int j = 0; j < genericArguments.Count; j++)
                {
                    genericArguments2.Add(this.ImportType(genericArguments[j], context));
                }
                return(genericInstanceType2);
            }

            case ElementType.FnPtr:
            {
                FunctionPointerType functionPointerType  = (FunctionPointerType)type;
                FunctionPointerType functionPointerType2 = new FunctionPointerType
                {
                    HasThis           = functionPointerType.HasThis,
                    ExplicitThis      = functionPointerType.ExplicitThis,
                    CallingConvention = functionPointerType.CallingConvention,
                    ReturnType        = this.ImportType(functionPointerType.ReturnType, context)
                };
                if (!functionPointerType.HasParameters)
                {
                    return(functionPointerType2);
                }
                for (int k = 0; k < functionPointerType.Parameters.Count; k++)
                {
                    functionPointerType2.Parameters.Add(new ParameterDefinition(this.ImportType(functionPointerType.Parameters[k].ParameterType, context)));
                }
                return(functionPointerType2);
            }

            case ElementType.SzArray:
            {
                ArrayType arrayType3 = (ArrayType)type;
                return(new ArrayType(this.ImportType(arrayType3.ElementType, context)));
            }

            case ElementType.MVar:
            {
                GenericParameter genericParameter2 = (GenericParameter)type;
                if (genericParameter2.DeclaringMethod == null)
                {
                    throw new InvalidOperationException();
                }
                return(context.MethodParameter(genericParameter2.DeclaringMethod.Name, genericParameter2.Position));
            }

            case ElementType.CModReqD:
            {
                RequiredModifierType requiredModifierType = (RequiredModifierType)type;
                return(new RequiredModifierType(this.ImportType(requiredModifierType.ModifierType, context), this.ImportType(requiredModifierType.ElementType, context)));
            }

            case ElementType.CModOpt:
            {
                OptionalModifierType optionalModifierType = (OptionalModifierType)type;
                return(new OptionalModifierType(this.ImportType(optionalModifierType.ModifierType, context), this.ImportType(optionalModifierType.ElementType, context)));
            }

            default:
                if (etype == ElementType.Sentinel)
                {
                    SentinelType sentinelType = (SentinelType)type;
                    return(new SentinelType(this.ImportType(sentinelType.ElementType, context)));
                }
                if (etype == ElementType.Pinned)
                {
                    PinnedType pinnedType = (PinnedType)type;
                    return(new PinnedType(this.ImportType(pinnedType.ElementType, context)));
                }
                break;
            }
            throw new NotSupportedException(type.etype.ToString());
        }