Esempio n. 1
0
        private void WriteArrayTypeSignature(ArrayType array)
        {
            this.WriteElementType(ElementType.Array);
            this.WriteTypeSignature(array.ElementType);
            Collection <ArrayDimension> dimensions = array.Dimensions;
            int count = dimensions.Count;

            base.WriteCompressedUInt32((uint)count);
            int num  = 0;
            int num2 = 0;

            for (int i = 0; i < count; i++)
            {
                ArrayDimension arrayDimension = dimensions[i];
                if (arrayDimension.UpperBound.HasValue)
                {
                    num++;
                    num2++;
                }
                else
                {
                    if (arrayDimension.LowerBound.HasValue)
                    {
                        num2++;
                    }
                }
            }
            int[] array2 = new int[num];
            int[] array3 = new int[num2];
            for (int j = 0; j < num2; j++)
            {
                ArrayDimension arrayDimension2 = dimensions[j];
                array3[j] = arrayDimension2.LowerBound.GetValueOrDefault();
                if (arrayDimension2.UpperBound.HasValue)
                {
                    array2[j] = arrayDimension2.UpperBound.Value - array3[j] + 1;
                }
            }
            base.WriteCompressedUInt32((uint)num);
            for (int k = 0; k < num; k++)
            {
                base.WriteCompressedUInt32((uint)array2[k]);
            }
            base.WriteCompressedUInt32((uint)num2);
            for (int l = 0; l < num2; l++)
            {
                base.WriteCompressedInt32(array3[l]);
            }
        }
Esempio n. 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());
        }