Esempio n. 1
0
        private TypeReference ImportTypeSpecification(TypeReference type, ImportGenericContext context)
        {
            ElementType elementType = type.etype;

            if (elementType > ElementType.CModOpt)
            {
                if (elementType == ElementType.Sentinel)
                {
                    SentinelType sentinelType = (SentinelType)type;
                    return(new SentinelType(this.ImportType(sentinelType.ElementType, context)));
                }
                if (elementType == ElementType.Pinned)
                {
                    PinnedType pinnedType = (PinnedType)type;
                    return(new PinnedType(this.ImportType(pinnedType.ElementType, context)));
                }
            }
            else
            {
                switch (elementType)
                {
                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:
                {
                    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 arrayType1 = new ArrayType(this.ImportType(arrayType.ElementType, context));
                    if (arrayType.IsVector)
                    {
                        return(arrayType1);
                    }
                    Collection <ArrayDimension> dimensions      = arrayType.Dimensions;
                    Collection <ArrayDimension> arrayDimensions = arrayType1.Dimensions;
                    arrayDimensions.Clear();
                    for (int i = 0; i < dimensions.Count; i++)
                    {
                        ArrayDimension item = dimensions[i];
                        arrayDimensions.Add(new ArrayDimension(item.LowerBound, item.UpperBound));
                    }
                    return(arrayType1);
                }

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

                default:
                {
                    switch (elementType)
                    {
                    case ElementType.SzArray:
                    {
                        ArrayType arrayType2 = (ArrayType)type;
                        return(new ArrayType(this.ImportType(arrayType2.ElementType, context)));
                    }

                    case ElementType.MVar:
                    {
                        GenericParameter genericParameter1 = (GenericParameter)type;
                        if (genericParameter1.DeclaringMethod == null)
                        {
                            throw new InvalidOperationException();
                        }
                        return(context.MethodParameter(context.NormalizeMethodName(genericParameter1.DeclaringMethod), genericParameter1.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)));
                    }
                    }
                    break;
                }
                }
            }
            throw new NotSupportedException(type.etype.ToString());
        }
Esempio n. 2
0
        TypeReference ImportTypeSpecification(TypeReference type, ImportGenericContext context)
        {
            switch (type.etype)
            {
            case ElementType.SzArray:
                var vector = (ArrayType)type;
                return(new ArrayType(ImportType(vector.ElementType, context)));

            case ElementType.Ptr:
                var pointer = (PointerType)type;
                return(new PointerType(ImportType(pointer.ElementType, context)));

            case ElementType.ByRef:
                var byref = (ByReferenceType)type;
                return(new ByReferenceType(ImportType(byref.ElementType, context)));

            case ElementType.Pinned:
                var pinned = (PinnedType)type;
                return(new PinnedType(ImportType(pinned.ElementType, context)));

            case ElementType.Sentinel:
                var sentinel = (SentinelType)type;
                return(new SentinelType(ImportType(sentinel.ElementType, context)));

            case ElementType.FnPtr:
                var fnptr          = (FunctionPointerType)type;
                var imported_fnptr = new FunctionPointerType()
                {
                    HasThis           = fnptr.HasThis,
                    ExplicitThis      = fnptr.ExplicitThis,
                    CallingConvention = fnptr.CallingConvention,
                    ReturnType        = ImportType(fnptr.ReturnType, context),
                };

                if (!fnptr.HasParameters)
                {
                    return(imported_fnptr);
                }

                for (int i = 0; i < fnptr.Parameters.Count; i++)
                {
                    imported_fnptr.Parameters.Add(new ParameterDefinition(
                                                      ImportType(fnptr.Parameters [i].ParameterType, context)));
                }

                return(imported_fnptr);

            case ElementType.CModOpt:
                var modopt = (OptionalModifierType)type;
                return(new OptionalModifierType(
                           ImportType(modopt.ModifierType, context),
                           ImportType(modopt.ElementType, context)));

            case ElementType.CModReqD:
                var modreq = (RequiredModifierType)type;
                return(new RequiredModifierType(
                           ImportType(modreq.ModifierType, context),
                           ImportType(modreq.ElementType, context)));

            case ElementType.Array:
                var array          = (ArrayType)type;
                var imported_array = new ArrayType(ImportType(array.ElementType, context));
                if (array.IsVector)
                {
                    return(imported_array);
                }

                var dimensions          = array.Dimensions;
                var imported_dimensions = imported_array.Dimensions;

                imported_dimensions.Clear();

                for (int i = 0; i < dimensions.Count; i++)
                {
                    var dimension = dimensions [i];

                    imported_dimensions.Add(new ArrayDimension(dimension.LowerBound, dimension.UpperBound));
                }

                return(imported_array);

            case ElementType.GenericInst:
                var instance          = (GenericInstanceType)type;
                var element_type      = ImportType(instance.ElementType, context);
                var imported_instance = new GenericInstanceType(element_type);

                var arguments          = instance.GenericArguments;
                var imported_arguments = imported_instance.GenericArguments;

                for (int i = 0; i < arguments.Count; i++)
                {
                    imported_arguments.Add(ImportType(arguments [i], context));
                }

                return(imported_instance);

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

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

            throw new NotSupportedException(type.etype.ToString());
        }
Esempio n. 3
0
        private TypeReference ImportTypeSpecification(TypeReference type, ImportGenericContext context)
        {
            switch (type.etype)
            {
            case ElementType.SzArray:
            {
                ArrayType arrayType = (ArrayType)type;
                return(new ArrayType(ImportType(arrayType.ElementType, context)));
            }

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

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

            case ElementType.Pinned:
            {
                PinnedType pinnedType = (PinnedType)type;
                return(new PinnedType(ImportType(pinnedType.ElementType, context)));
            }

            case ElementType.Sentinel:
            {
                SentinelType sentinelType = (SentinelType)type;
                return(new SentinelType(ImportType(sentinelType.ElementType, context)));
            }

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

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

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

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

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

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

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

            default:
                throw new NotSupportedException(type.etype.ToString());
            }
        }