public MetadataOnlyPropertyInfo(MetadataOnlyModule resolver, Token propToken, Type[] typeArgs, Type[] methodArgs)
        {
            int num;
            EmbeddedBlobPointer embeddedBlobPointer;
            int                num1;
            int                num2;
            UnusedIntPtr       unusedIntPtr;
            int                num3;
            PropertyAttributes propertyAttribute;
            Token              token;
            Token              token1;
            Token              token2;
            uint               num4;

            this.m_resolver      = resolver;
            this.m_PropertyToken = propToken;
            this.m_context       = new GenericContext(typeArgs, methodArgs);
            IMetadataImport rawImport     = this.m_resolver.RawImport;
            StringBuilder   stringBuilder = new StringBuilder(256);

            rawImport.GetPropertyProps(this.m_PropertyToken, out this.m_declaringClassToken, null, 0, out num, out propertyAttribute, out embeddedBlobPointer, out num1, out num2, out unusedIntPtr, out num3, out token, out token1, out token2, 1, out num4);
            this.m_attrib          = propertyAttribute;
            stringBuilder.Capacity = num;
            rawImport.GetPropertyProps(this.m_PropertyToken, out this.m_declaringClassToken, stringBuilder, num, out num, out propertyAttribute, out embeddedBlobPointer, out num1, out num2, out unusedIntPtr, out num3, out token, out token1, out token2, 1, out num4);
            this.m_name = stringBuilder.ToString();
            byte[] numArray = this.m_resolver.ReadEmbeddedBlob(embeddedBlobPointer, num1);
            int    num5     = 0;

            SignatureUtil.ExtractCallingConvention(numArray, ref num5);
            SignatureUtil.ExtractInt(numArray, ref num5);
            this.m_propertyType = SignatureUtil.ExtractType(numArray, ref num5, this.m_resolver, this.m_context);
            this.m_setterToken  = token;
            this.m_getterToken  = token1;
        }
예제 #2
0
        protected override Type GetResolvedTypeWorker()
        {
            byte[] blob = this.Blob;
            int    num  = 0;
            Type   type = SignatureUtil.ExtractType(blob, ref num, this.Resolver, this.m_context);

            return(type);
        }
예제 #3
0
        internal static MethodSignatureDescriptor ExtractMethodSignature(SignatureBlob methodSignatureBlob, MetadataOnlyModule resolver, GenericContext context)
        {
            byte[] signatureAsByteArray = methodSignatureBlob.GetSignatureAsByteArray();
            int    num = 0;
            MethodSignatureDescriptor methodSignatureDescriptor = new MethodSignatureDescriptor()
            {
                ReturnParameter       = new TypeSignatureDescriptor(),
                GenericParameterCount = 0,
                CallingConvention     = SignatureUtil.ExtractCallingConvention(signatureAsByteArray, ref num)
            };
            bool callingConvention = (methodSignatureDescriptor.CallingConvention & Microsoft.MetadataReader.CorCallingConvention.ExplicitThis) != Microsoft.MetadataReader.CorCallingConvention.Default;

            if ((methodSignatureDescriptor.CallingConvention & Microsoft.MetadataReader.CorCallingConvention.Generic) != Microsoft.MetadataReader.CorCallingConvention.Default)
            {
                int num1 = SignatureUtil.ExtractInt(signatureAsByteArray, ref num);
                if (num1 <= 0)
                {
                    CultureInfo invariantCulture         = CultureInfo.InvariantCulture;
                    object[]    invalidMetadataSignature = new object[] { MetadataStringTable.InvalidMetadataSignature, MetadataStringTable.ExpectedPositiveNumberOfGenericParameters };
                    throw new ArgumentException(string.Format(invariantCulture, "{0} {1}", invalidMetadataSignature));
                }
                context = context.VerifyAndUpdateMethodArguments(num1);
                methodSignatureDescriptor.GenericParameterCount = num1;
            }
            int             num2           = SignatureUtil.ExtractInt(signatureAsByteArray, ref num);
            bool            flag           = false;
            CustomModifiers customModifier = SignatureUtil.ExtractCustomModifiers(signatureAsByteArray, ref num, resolver, context);

            methodSignatureDescriptor.ReturnParameter = SignatureUtil.ExtractType(signatureAsByteArray, ref num, resolver, context, flag);
            methodSignatureDescriptor.ReturnParameter.CustomModifiers = customModifier;
            if (callingConvention)
            {
                SignatureUtil.ExtractType(signatureAsByteArray, ref num, resolver, context);
                num2--;
            }
            methodSignatureDescriptor.Parameters = new TypeSignatureDescriptor[num2];
            for (int i = 0; i < num2; i++)
            {
                customModifier = SignatureUtil.ExtractCustomModifiers(signatureAsByteArray, ref num, resolver, context);
                methodSignatureDescriptor.Parameters[i] = SignatureUtil.ExtractType(signatureAsByteArray, ref num, resolver, context, flag);
                methodSignatureDescriptor.Parameters[i].CustomModifiers = customModifier;
            }
            if (num != (int)signatureAsByteArray.Length)
            {
                CultureInfo cultureInfo = CultureInfo.InvariantCulture;
                object[]    objArray    = new object[] { MetadataStringTable.InvalidMetadataSignature, MetadataStringTable.ExtraInformationAfterLastParameter };
                throw new ArgumentException(string.Format(cultureInfo, "{0} {1}", objArray));
            }
            return(methodSignatureDescriptor);
        }
예제 #4
0
        public MetadataOnlyFieldInfo(MetadataOnlyModule resolver, Token fieldDefToken, Type[] typeArgs, Type[] methodArgs)
        {
            int num;
            EmbeddedBlobPointer embeddedBlobPointer;
            int             num1;
            int             num2;
            IntPtr          intPtr;
            int             num3;
            FieldAttributes fieldAttribute;

            this.m_resolver      = resolver;
            this.m_fieldDefToken = fieldDefToken;
            if (typeArgs != null || methodArgs != null)
            {
                this.m_context = new GenericContext(typeArgs, methodArgs);
            }
            IMetadataImport rawImport     = this.m_resolver.RawImport;
            StringBuilder   stringBuilder = new StringBuilder(256);

            rawImport.GetFieldProps(this.m_fieldDefToken, out this.m_declaringClassToken, null, 0, out num, out fieldAttribute, out embeddedBlobPointer, out num1, out num2, out intPtr, out num3);
            this.m_attrib          = fieldAttribute;
            stringBuilder.Capacity = num;
            rawImport.GetFieldProps(this.m_fieldDefToken, out this.m_declaringClassToken, stringBuilder, num, out num, out fieldAttribute, out embeddedBlobPointer, out num1, out num2, out intPtr, out num3);
            this.m_attrib = fieldAttribute;
            this.m_name   = stringBuilder.ToString();
            byte[] numArray = this.m_resolver.ReadEmbeddedBlob(embeddedBlobPointer, num1);
            int    num4     = 0;

            SignatureUtil.ExtractCallingConvention(numArray, ref num4);
            this.m_customModifiers = SignatureUtil.ExtractCustomModifiers(numArray, ref num4, this.m_resolver, this.m_context);
            if (this.m_resolver.RawImport.IsValidToken((uint)this.m_declaringClassToken))
            {
                Type type = this.m_resolver.ResolveType(this.m_declaringClassToken);
                if (type.IsGenericType && (this.m_context == null || this.m_context.TypeArgs == null || (int)this.m_context.TypeArgs.Length == 0))
                {
                    if (this.m_context != null)
                    {
                        this.m_context = new GenericContext(type.GetGenericArguments(), this.m_context.MethodArgs);
                    }
                    else
                    {
                        this.m_context = new GenericContext(type.GetGenericArguments(), null);
                    }
                }
            }
            this.m_fieldType = SignatureUtil.ExtractType(numArray, ref num4, this.m_resolver, this.m_context);
        }
예제 #5
0
        internal static TypeSignatureDescriptor ExtractType(byte[] sig, ref int index, MetadataOnlyModule resolver, GenericContext context, bool fAllowPinned)
        {
            TypeSignatureDescriptor typeSignatureDescriptor = new TypeSignatureDescriptor()
            {
                IsPinned = false
            };

            System.Reflection.Adds.CorElementType corElementType = SignatureUtil.ExtractElementType(sig, ref index);
            switch (corElementType)
            {
            case System.Reflection.Adds.CorElementType.End:
            case System.Reflection.Adds.CorElementType.Array | System.Reflection.Adds.CorElementType.Bool | System.Reflection.Adds.CorElementType.Byref | System.Reflection.Adds.CorElementType.Char | System.Reflection.Adds.CorElementType.Class | System.Reflection.Adds.CorElementType.SByte | System.Reflection.Adds.CorElementType.Short | System.Reflection.Adds.CorElementType.TypedByRef | System.Reflection.Adds.CorElementType.Byte | System.Reflection.Adds.CorElementType.UShort | System.Reflection.Adds.CorElementType.ValueType | System.Reflection.Adds.CorElementType.Void | System.Reflection.Adds.CorElementType.TypeVar | System.Reflection.Adds.CorElementType.GenericInstantiation:
            case System.Reflection.Adds.CorElementType.Bool | System.Reflection.Adds.CorElementType.Byref | System.Reflection.Adds.CorElementType.Class | System.Reflection.Adds.CorElementType.IntPtr | System.Reflection.Adds.CorElementType.Int | System.Reflection.Adds.CorElementType.Long:
            case System.Reflection.Adds.CorElementType.Internal:
            case System.Reflection.Adds.CorElementType.Max:
            case System.Reflection.Adds.CorElementType.Bool | System.Reflection.Adds.CorElementType.Char | System.Reflection.Adds.CorElementType.CModOpt | System.Reflection.Adds.CorElementType.Internal | System.Reflection.Adds.CorElementType.Max | System.Reflection.Adds.CorElementType.Void:
            case System.Reflection.Adds.CorElementType.CModOpt | System.Reflection.Adds.CorElementType.SByte:
            case System.Reflection.Adds.CorElementType.CModOpt | System.Reflection.Adds.CorElementType.SByte | System.Reflection.Adds.CorElementType.Internal | System.Reflection.Adds.CorElementType.Byte | System.Reflection.Adds.CorElementType.Void:
            case System.Reflection.Adds.CorElementType.Bool | System.Reflection.Adds.CorElementType.CModOpt | System.Reflection.Adds.CorElementType.SByte | System.Reflection.Adds.CorElementType.Short | System.Reflection.Adds.CorElementType.Max:
            case System.Reflection.Adds.CorElementType.Bool | System.Reflection.Adds.CorElementType.Char | System.Reflection.Adds.CorElementType.CModOpt | System.Reflection.Adds.CorElementType.SByte | System.Reflection.Adds.CorElementType.Short | System.Reflection.Adds.CorElementType.Internal | System.Reflection.Adds.CorElementType.Max | System.Reflection.Adds.CorElementType.Byte | System.Reflection.Adds.CorElementType.UShort | System.Reflection.Adds.CorElementType.Void:
            case System.Reflection.Adds.CorElementType.CModOpt | System.Reflection.Adds.CorElementType.Int:
            case System.Reflection.Adds.CorElementType.CModOpt | System.Reflection.Adds.CorElementType.Int | System.Reflection.Adds.CorElementType.Internal | System.Reflection.Adds.CorElementType.UInt | System.Reflection.Adds.CorElementType.Void:
            case System.Reflection.Adds.CorElementType.Bool | System.Reflection.Adds.CorElementType.CModOpt | System.Reflection.Adds.CorElementType.Int | System.Reflection.Adds.CorElementType.Long | System.Reflection.Adds.CorElementType.Max:
            case System.Reflection.Adds.CorElementType.Bool | System.Reflection.Adds.CorElementType.Char | System.Reflection.Adds.CorElementType.CModOpt | System.Reflection.Adds.CorElementType.Int | System.Reflection.Adds.CorElementType.Long | System.Reflection.Adds.CorElementType.Internal | System.Reflection.Adds.CorElementType.Max | System.Reflection.Adds.CorElementType.UInt | System.Reflection.Adds.CorElementType.ULong | System.Reflection.Adds.CorElementType.Void:
            case System.Reflection.Adds.CorElementType.CModOpt | System.Reflection.Adds.CorElementType.SByte | System.Reflection.Adds.CorElementType.Int | System.Reflection.Adds.CorElementType.Float:
            case System.Reflection.Adds.CorElementType.CModOpt | System.Reflection.Adds.CorElementType.SByte | System.Reflection.Adds.CorElementType.Int | System.Reflection.Adds.CorElementType.Internal | System.Reflection.Adds.CorElementType.Float | System.Reflection.Adds.CorElementType.Double | System.Reflection.Adds.CorElementType.Byte | System.Reflection.Adds.CorElementType.UInt | System.Reflection.Adds.CorElementType.Void:
            case System.Reflection.Adds.CorElementType.Bool | System.Reflection.Adds.CorElementType.CModOpt | System.Reflection.Adds.CorElementType.SByte | System.Reflection.Adds.CorElementType.Short | System.Reflection.Adds.CorElementType.Int | System.Reflection.Adds.CorElementType.Long | System.Reflection.Adds.CorElementType.Max | System.Reflection.Adds.CorElementType.Float | System.Reflection.Adds.CorElementType.String:
            case System.Reflection.Adds.CorElementType.Bool | System.Reflection.Adds.CorElementType.Char | System.Reflection.Adds.CorElementType.CModOpt | System.Reflection.Adds.CorElementType.SByte | System.Reflection.Adds.CorElementType.Short | System.Reflection.Adds.CorElementType.Int | System.Reflection.Adds.CorElementType.Long | System.Reflection.Adds.CorElementType.Internal | System.Reflection.Adds.CorElementType.Max | System.Reflection.Adds.CorElementType.Pointer | System.Reflection.Adds.CorElementType.Float | System.Reflection.Adds.CorElementType.Double | System.Reflection.Adds.CorElementType.String | System.Reflection.Adds.CorElementType.Byte | System.Reflection.Adds.CorElementType.UShort | System.Reflection.Adds.CorElementType.UInt | System.Reflection.Adds.CorElementType.ULong | System.Reflection.Adds.CorElementType.Void:
            case System.Reflection.Adds.CorElementType.Byref | System.Reflection.Adds.CorElementType.CModOpt:
            case System.Reflection.Adds.CorElementType.Byref | System.Reflection.Adds.CorElementType.CModOpt | System.Reflection.Adds.CorElementType.Internal | System.Reflection.Adds.CorElementType.ValueType | System.Reflection.Adds.CorElementType.Void:
            case System.Reflection.Adds.CorElementType.Bool | System.Reflection.Adds.CorElementType.Byref | System.Reflection.Adds.CorElementType.Class | System.Reflection.Adds.CorElementType.CModOpt | System.Reflection.Adds.CorElementType.Max:
            case System.Reflection.Adds.CorElementType.Bool | System.Reflection.Adds.CorElementType.Byref | System.Reflection.Adds.CorElementType.Char | System.Reflection.Adds.CorElementType.Class | System.Reflection.Adds.CorElementType.CModOpt | System.Reflection.Adds.CorElementType.Internal | System.Reflection.Adds.CorElementType.Max | System.Reflection.Adds.CorElementType.ValueType | System.Reflection.Adds.CorElementType.Void | System.Reflection.Adds.CorElementType.TypeVar:
            case System.Reflection.Adds.CorElementType.Array | System.Reflection.Adds.CorElementType.Byref | System.Reflection.Adds.CorElementType.CModOpt | System.Reflection.Adds.CorElementType.SByte:
            case System.Reflection.Adds.CorElementType.Array | System.Reflection.Adds.CorElementType.Byref | System.Reflection.Adds.CorElementType.CModOpt | System.Reflection.Adds.CorElementType.SByte | System.Reflection.Adds.CorElementType.Internal | System.Reflection.Adds.CorElementType.Byte | System.Reflection.Adds.CorElementType.ValueType | System.Reflection.Adds.CorElementType.Void | System.Reflection.Adds.CorElementType.GenericInstantiation:
            case System.Reflection.Adds.CorElementType.Array | System.Reflection.Adds.CorElementType.Bool | System.Reflection.Adds.CorElementType.Byref | System.Reflection.Adds.CorElementType.Class | System.Reflection.Adds.CorElementType.CModOpt | System.Reflection.Adds.CorElementType.SByte | System.Reflection.Adds.CorElementType.Short | System.Reflection.Adds.CorElementType.Max | System.Reflection.Adds.CorElementType.TypedByRef:
            case System.Reflection.Adds.CorElementType.Array | System.Reflection.Adds.CorElementType.Bool | System.Reflection.Adds.CorElementType.Byref | System.Reflection.Adds.CorElementType.Char | System.Reflection.Adds.CorElementType.Class | System.Reflection.Adds.CorElementType.CModOpt | System.Reflection.Adds.CorElementType.SByte | System.Reflection.Adds.CorElementType.Short | System.Reflection.Adds.CorElementType.Internal | System.Reflection.Adds.CorElementType.Max | System.Reflection.Adds.CorElementType.TypedByRef | System.Reflection.Adds.CorElementType.Byte | System.Reflection.Adds.CorElementType.UShort | System.Reflection.Adds.CorElementType.ValueType | System.Reflection.Adds.CorElementType.Void | System.Reflection.Adds.CorElementType.TypeVar | System.Reflection.Adds.CorElementType.GenericInstantiation:
            case System.Reflection.Adds.CorElementType.Byref | System.Reflection.Adds.CorElementType.CModOpt | System.Reflection.Adds.CorElementType.IntPtr | System.Reflection.Adds.CorElementType.Int:
            case System.Reflection.Adds.CorElementType.Byref | System.Reflection.Adds.CorElementType.CModOpt | System.Reflection.Adds.CorElementType.IntPtr | System.Reflection.Adds.CorElementType.Int | System.Reflection.Adds.CorElementType.Internal | System.Reflection.Adds.CorElementType.UIntPtr | System.Reflection.Adds.CorElementType.UInt | System.Reflection.Adds.CorElementType.ValueType | System.Reflection.Adds.CorElementType.Void:
            case System.Reflection.Adds.CorElementType.Bool | System.Reflection.Adds.CorElementType.Byref | System.Reflection.Adds.CorElementType.Class | System.Reflection.Adds.CorElementType.CModOpt | System.Reflection.Adds.CorElementType.IntPtr | System.Reflection.Adds.CorElementType.Int | System.Reflection.Adds.CorElementType.Long | System.Reflection.Adds.CorElementType.Max:
            case System.Reflection.Adds.CorElementType.Bool | System.Reflection.Adds.CorElementType.Byref | System.Reflection.Adds.CorElementType.Char | System.Reflection.Adds.CorElementType.Class | System.Reflection.Adds.CorElementType.CModOpt | System.Reflection.Adds.CorElementType.FnPtr | System.Reflection.Adds.CorElementType.IntPtr | System.Reflection.Adds.CorElementType.Int | System.Reflection.Adds.CorElementType.Long | System.Reflection.Adds.CorElementType.Internal | System.Reflection.Adds.CorElementType.Max | System.Reflection.Adds.CorElementType.UIntPtr | System.Reflection.Adds.CorElementType.UInt | System.Reflection.Adds.CorElementType.ULong | System.Reflection.Adds.CorElementType.ValueType | System.Reflection.Adds.CorElementType.Void | System.Reflection.Adds.CorElementType.TypeVar:
            case System.Reflection.Adds.CorElementType.Array | System.Reflection.Adds.CorElementType.Byref | System.Reflection.Adds.CorElementType.CModOpt | System.Reflection.Adds.CorElementType.IntPtr | System.Reflection.Adds.CorElementType.SByte | System.Reflection.Adds.CorElementType.Int | System.Reflection.Adds.CorElementType.Object | System.Reflection.Adds.CorElementType.Float:
            case System.Reflection.Adds.CorElementType.Array | System.Reflection.Adds.CorElementType.Byref | System.Reflection.Adds.CorElementType.CModOpt | System.Reflection.Adds.CorElementType.IntPtr | System.Reflection.Adds.CorElementType.SByte | System.Reflection.Adds.CorElementType.Int | System.Reflection.Adds.CorElementType.Internal | System.Reflection.Adds.CorElementType.Object | System.Reflection.Adds.CorElementType.Float | System.Reflection.Adds.CorElementType.Double | System.Reflection.Adds.CorElementType.SzArray | System.Reflection.Adds.CorElementType.UIntPtr | System.Reflection.Adds.CorElementType.Byte | System.Reflection.Adds.CorElementType.UInt | System.Reflection.Adds.CorElementType.ValueType | System.Reflection.Adds.CorElementType.Void | System.Reflection.Adds.CorElementType.GenericInstantiation:
            case System.Reflection.Adds.CorElementType.Array | System.Reflection.Adds.CorElementType.Bool | System.Reflection.Adds.CorElementType.Byref | System.Reflection.Adds.CorElementType.Class | System.Reflection.Adds.CorElementType.CModOpt | System.Reflection.Adds.CorElementType.IntPtr | System.Reflection.Adds.CorElementType.SByte | System.Reflection.Adds.CorElementType.Short | System.Reflection.Adds.CorElementType.Int | System.Reflection.Adds.CorElementType.Long | System.Reflection.Adds.CorElementType.Max | System.Reflection.Adds.CorElementType.Object | System.Reflection.Adds.CorElementType.Float | System.Reflection.Adds.CorElementType.String | System.Reflection.Adds.CorElementType.TypedByRef | System.Reflection.Adds.CorElementType.MethodVar:
            case System.Reflection.Adds.CorElementType.Array | System.Reflection.Adds.CorElementType.Bool | System.Reflection.Adds.CorElementType.Byref | System.Reflection.Adds.CorElementType.Char | System.Reflection.Adds.CorElementType.Class | System.Reflection.Adds.CorElementType.CModOpt | System.Reflection.Adds.CorElementType.CModReqd | System.Reflection.Adds.CorElementType.FnPtr | System.Reflection.Adds.CorElementType.IntPtr | System.Reflection.Adds.CorElementType.SByte | System.Reflection.Adds.CorElementType.Short | System.Reflection.Adds.CorElementType.Int | System.Reflection.Adds.CorElementType.Long | System.Reflection.Adds.CorElementType.Internal | System.Reflection.Adds.CorElementType.Max | System.Reflection.Adds.CorElementType.Object | System.Reflection.Adds.CorElementType.Pointer | System.Reflection.Adds.CorElementType.Float | System.Reflection.Adds.CorElementType.Double | System.Reflection.Adds.CorElementType.String | System.Reflection.Adds.CorElementType.SzArray | System.Reflection.Adds.CorElementType.TypedByRef | System.Reflection.Adds.CorElementType.UIntPtr | System.Reflection.Adds.CorElementType.Byte | System.Reflection.Adds.CorElementType.UShort | System.Reflection.Adds.CorElementType.UInt | System.Reflection.Adds.CorElementType.ULong | System.Reflection.Adds.CorElementType.ValueType | System.Reflection.Adds.CorElementType.Void | System.Reflection.Adds.CorElementType.TypeVar | System.Reflection.Adds.CorElementType.MethodVar | System.Reflection.Adds.CorElementType.GenericInstantiation:
            case System.Reflection.Adds.CorElementType.Modifier:
            case System.Reflection.Adds.CorElementType.Sentinel:
            case System.Reflection.Adds.CorElementType.Bool | System.Reflection.Adds.CorElementType.Modifier:
            case System.Reflection.Adds.CorElementType.Bool | System.Reflection.Adds.CorElementType.Char | System.Reflection.Adds.CorElementType.Modifier | System.Reflection.Adds.CorElementType.Sentinel | System.Reflection.Adds.CorElementType.Void:
            case System.Reflection.Adds.CorElementType.SByte | System.Reflection.Adds.CorElementType.Modifier:
            {
                throw new ArgumentException(MetadataStringTable.IncorrectElementTypeValue);
            }

            case System.Reflection.Adds.CorElementType.Void:
            case System.Reflection.Adds.CorElementType.Bool:
            case System.Reflection.Adds.CorElementType.Char:
            case System.Reflection.Adds.CorElementType.SByte:
            case System.Reflection.Adds.CorElementType.Byte:
            case System.Reflection.Adds.CorElementType.Short:
            case System.Reflection.Adds.CorElementType.UShort:
            case System.Reflection.Adds.CorElementType.Int:
            case System.Reflection.Adds.CorElementType.UInt:
            case System.Reflection.Adds.CorElementType.Long:
            case System.Reflection.Adds.CorElementType.ULong:
            case System.Reflection.Adds.CorElementType.Float:
            case System.Reflection.Adds.CorElementType.Double:
            case System.Reflection.Adds.CorElementType.String:
            case System.Reflection.Adds.CorElementType.IntPtr:
            case System.Reflection.Adds.CorElementType.UIntPtr:
            case System.Reflection.Adds.CorElementType.Object:
            {
                typeSignatureDescriptor.Type = resolver.AssemblyResolver.GetBuiltInType(corElementType);
                break;
            }

            case System.Reflection.Adds.CorElementType.Pointer:
            {
                typeSignatureDescriptor.Type = SignatureUtil.ExtractType(sig, ref index, resolver, context).MakePointerType();
                break;
            }

            case System.Reflection.Adds.CorElementType.Byref:
            {
                typeSignatureDescriptor.Type = SignatureUtil.ExtractType(sig, ref index, resolver, context).MakeByRefType();
                break;
            }

            case System.Reflection.Adds.CorElementType.ValueType:
            case System.Reflection.Adds.CorElementType.Class:
            {
                Token token = SignatureUtil.ExtractToken(sig, ref index);
                typeSignatureDescriptor.Type = resolver.ResolveTypeTokenInternal(token, context);
                break;
            }

            case System.Reflection.Adds.CorElementType.TypeVar:
            {
                int num = SignatureUtil.ExtractInt(sig, ref index);
                if (GenericContext.IsNullOrEmptyTypeArgs(context))
                {
                    throw new ArgumentException(MetadataStringTable.TypeArgumentCannotBeResolved);
                }
                typeSignatureDescriptor.Type = context.TypeArgs[num];
                break;
            }

            case System.Reflection.Adds.CorElementType.Array:
            {
                Type type = SignatureUtil.ExtractType(sig, ref index, resolver, context);
                int  num1 = SignatureUtil.ExtractInt(sig, ref index);
                int  num2 = SignatureUtil.ExtractInt(sig, ref index);
                for (int i = 0; i < num2; i++)
                {
                    SignatureUtil.ExtractInt(sig, ref index);
                }
                int num3 = SignatureUtil.ExtractInt(sig, ref index);
                for (int j = 0; j < num3; j++)
                {
                    SignatureUtil.ExtractInt(sig, ref index);
                }
                typeSignatureDescriptor.Type = type.MakeArrayType(num1);
                break;
            }

            case System.Reflection.Adds.CorElementType.GenericInstantiation:
            {
                Type   type1     = SignatureUtil.ExtractType(sig, ref index, resolver, null);
                Type[] typeArray = new Type[SignatureUtil.ExtractInt(sig, ref index)];
                for (int k = 0; k < (int)typeArray.Length; k++)
                {
                    typeArray[k] = SignatureUtil.ExtractType(sig, ref index, resolver, context);
                }
                typeSignatureDescriptor.Type = type1.MakeGenericType(typeArray);
                break;
            }

            case System.Reflection.Adds.CorElementType.TypedByRef:
            {
                typeSignatureDescriptor.Type = resolver.AssemblyResolver.GetTypeXFromName("System.TypedReference");
                break;
            }

            case System.Reflection.Adds.CorElementType.FnPtr:
            {
                SignatureUtil.ExtractCallingConvention(sig, ref index);
                int num4 = SignatureUtil.ExtractInt(sig, ref index);
                SignatureUtil.ExtractType(sig, ref index, resolver, context);
                for (int l = 0; l < num4; l++)
                {
                    SignatureUtil.ExtractType(sig, ref index, resolver, context);
                }
                typeSignatureDescriptor.Type = resolver.AssemblyResolver.GetBuiltInType(System.Reflection.Adds.CorElementType.IntPtr);
                break;
            }

            case System.Reflection.Adds.CorElementType.SzArray:
            {
                typeSignatureDescriptor.Type = SignatureUtil.ExtractType(sig, ref index, resolver, context).MakeArrayType();
                break;
            }

            case System.Reflection.Adds.CorElementType.MethodVar:
            {
                int num5 = SignatureUtil.ExtractInt(sig, ref index);
                if (GenericContext.IsNullOrEmptyMethodArgs(context))
                {
                    throw new ArgumentException(MetadataStringTable.TypeArgumentCannotBeResolved);
                }
                typeSignatureDescriptor.Type = context.MethodArgs[num5];
                break;
            }

            case System.Reflection.Adds.CorElementType.CModReqd:
            {
                Token token1 = SignatureUtil.ExtractToken(sig, ref index);
                resolver.ResolveTypeTokenInternal(token1, context);
                typeSignatureDescriptor.Type = SignatureUtil.ExtractType(sig, ref index, resolver, context);
                break;
            }

            case System.Reflection.Adds.CorElementType.CModOpt:
            {
                Token token2 = SignatureUtil.ExtractToken(sig, ref index);
                resolver.ResolveTypeTokenInternal(token2, context);
                typeSignatureDescriptor.Type = SignatureUtil.ExtractType(sig, ref index, resolver, context);
                break;
            }

            case System.Reflection.Adds.CorElementType.Pinned:
            {
                typeSignatureDescriptor.IsPinned = true;
                typeSignatureDescriptor.Type     = SignatureUtil.ExtractType(sig, ref index, resolver, context);
                break;
            }

            default:
            {
                throw new ArgumentException(MetadataStringTable.IncorrectElementTypeValue);
            }
            }
            return(typeSignatureDescriptor);
        }
예제 #6
0
        internal static Type ExtractType(byte[] sig, ref int index, MetadataOnlyModule resolver, GenericContext context)
        {
            TypeSignatureDescriptor typeSignatureDescriptor = SignatureUtil.ExtractType(sig, ref index, resolver, context, false);

            return(typeSignatureDescriptor.Type);
        }
예제 #7
0
        private object ParseDefaultValue()
        {
            int num;
            EmbeddedBlobPointer embeddedBlobPointer;
            int             num1;
            int             num2;
            IntPtr          intPtr;
            int             num3;
            FieldAttributes fieldAttribute;
            int             num4;
            IMetadataImport rawImport = this.m_resolver.RawImport;

            rawImport.GetFieldProps(this.m_fieldDefToken, out num4, null, 0, out num, out fieldAttribute, out embeddedBlobPointer, out num1, out num2, out intPtr, out num3);
            byte[] numArray = this.m_resolver.ReadEmbeddedBlob(embeddedBlobPointer, num1);
            int    num5     = 0;

            SignatureUtil.ExtractCallingConvention(numArray, ref num5);
            System.Reflection.Adds.CorElementType corElementType = SignatureUtil.ExtractElementType(numArray, ref num5);
            if (corElementType == System.Reflection.Adds.CorElementType.ValueType)
            {
                SignatureUtil.ExtractToken(numArray, ref num5);
                corElementType = (System.Reflection.Adds.CorElementType)num2;
            }
            else if (corElementType == System.Reflection.Adds.CorElementType.GenericInstantiation)
            {
                SignatureUtil.ExtractType(numArray, ref num5, this.m_resolver, this.m_context);
                corElementType = (System.Reflection.Adds.CorElementType)num2;
            }
            switch (corElementType)
            {
            case System.Reflection.Adds.CorElementType.Bool:
            {
                if (Marshal.ReadByte(intPtr) == 0)
                {
                    return(false);
                }
                return(true);
            }

            case System.Reflection.Adds.CorElementType.Char:
            {
                return((char)Marshal.ReadInt16(intPtr));
            }

            case System.Reflection.Adds.CorElementType.SByte:
            {
                return((sbyte)Marshal.ReadByte(intPtr));
            }

            case System.Reflection.Adds.CorElementType.Byte:
            {
                return(Marshal.ReadByte(intPtr));
            }

            case System.Reflection.Adds.CorElementType.Short:
            {
                return(Marshal.ReadInt16(intPtr));
            }

            case System.Reflection.Adds.CorElementType.UShort:
            {
                return((ushort)Marshal.ReadInt16(intPtr));
            }

            case System.Reflection.Adds.CorElementType.Int:
            {
                return(Marshal.ReadInt32(intPtr));
            }

            case System.Reflection.Adds.CorElementType.UInt:
            {
                return((uint)Marshal.ReadInt32(intPtr));
            }

            case System.Reflection.Adds.CorElementType.Long:
            {
                return(Marshal.ReadInt64(intPtr));
            }

            case System.Reflection.Adds.CorElementType.ULong:
            {
                return((ulong)Marshal.ReadInt64(intPtr));
            }

            case System.Reflection.Adds.CorElementType.Float:
            {
                float[] singleArray = new float[1];
                Marshal.Copy(intPtr, singleArray, 0, 1);
                return(singleArray[0]);
            }

            case System.Reflection.Adds.CorElementType.Double:
            {
                double[] numArray1 = new double[1];
                Marshal.Copy(intPtr, numArray1, 0, 1);
                return(numArray1[0]);
            }

            case System.Reflection.Adds.CorElementType.String:
            {
                return(Marshal.PtrToStringAuto(intPtr, num3));
            }

            case System.Reflection.Adds.CorElementType.Pointer:
            case System.Reflection.Adds.CorElementType.Byref:
            case System.Reflection.Adds.CorElementType.ValueType:
            case System.Reflection.Adds.CorElementType.TypeVar:
            case System.Reflection.Adds.CorElementType.Array:
            case System.Reflection.Adds.CorElementType.GenericInstantiation:
            case System.Reflection.Adds.CorElementType.TypedByRef:
            case System.Reflection.Adds.CorElementType.Array | System.Reflection.Adds.CorElementType.Bool | System.Reflection.Adds.CorElementType.Byref | System.Reflection.Adds.CorElementType.Char | System.Reflection.Adds.CorElementType.Class | System.Reflection.Adds.CorElementType.SByte | System.Reflection.Adds.CorElementType.Short | System.Reflection.Adds.CorElementType.TypedByRef | System.Reflection.Adds.CorElementType.Byte | System.Reflection.Adds.CorElementType.UShort | System.Reflection.Adds.CorElementType.ValueType | System.Reflection.Adds.CorElementType.Void | System.Reflection.Adds.CorElementType.TypeVar | System.Reflection.Adds.CorElementType.GenericInstantiation:
            case System.Reflection.Adds.CorElementType.UIntPtr:
            {
                throw new InvalidOperationException(MetadataStringTable.IncorrectElementTypeValue);
            }

            case System.Reflection.Adds.CorElementType.Class:
            {
                return(null);
            }

            case System.Reflection.Adds.CorElementType.IntPtr:
            {
                return(Marshal.ReadIntPtr(intPtr));
            }

            default:
            {
                throw new InvalidOperationException(MetadataStringTable.IncorrectElementTypeValue);
            }
            }
        }