/// <summary>
        /// Decodes a type from within a signature from a BlobReader positioned immediately past the given SignatureTypeCode.
        /// </summary>
        /// <param name="blobReader">The blob reader.</param>
        /// <param name="typeCode">The SignatureTypeCode that immediately preceded the reader's current position.</param>
        /// <param name="provider">The type provider.</param>
        /// <returns>The decoded type.</returns>
        /// <exception cref="System.BadImageFormatException">The reader was not positioned at a valud signature type.</exception>
        private static TType DecodeType <TType>(ref BlobReader blobReader, int typeCode, ISignatureTypeProvider <TType> provider)
        {
            TType elementType;
            int   index;

            if (typeCode > byte.MaxValue)
            {
                typeCode = (int)SignatureTypeCode.Invalid;
            }
            switch (typeCode)
            {
            case (int)SignatureTypeCode.Boolean:
            case (int)SignatureTypeCode.Char:
            case (int)SignatureTypeCode.SByte:
            case (int)SignatureTypeCode.Byte:
            case (int)SignatureTypeCode.Int16:
            case (int)SignatureTypeCode.UInt16:
            case (int)SignatureTypeCode.Int32:
            case (int)SignatureTypeCode.UInt32:
            case (int)SignatureTypeCode.Int64:
            case (int)SignatureTypeCode.UInt64:
            case (int)SignatureTypeCode.Single:
            case (int)SignatureTypeCode.Double:
            case (int)SignatureTypeCode.IntPtr:
            case (int)SignatureTypeCode.UIntPtr:
            case (int)SignatureTypeCode.Object:
            case (int)SignatureTypeCode.String:
            case (int)SignatureTypeCode.Void:
            case (int)SignatureTypeCode.TypedReference:
                return(provider.GetPrimitiveType((PrimitiveTypeCode)typeCode));

            case (int)SignatureTypeCode.Pointer:
                elementType = DecodeType(ref blobReader, provider);
                return(provider.GetPointerType(elementType));

            case (int)SignatureTypeCode.ByReference:
                elementType = DecodeType(ref blobReader, provider);
                return(provider.GetByReferenceType(elementType));

            case (int)SignatureTypeCode.Pinned:
                elementType = DecodeType(ref blobReader, provider);
                return(provider.GetPinnedType(elementType));

            case (int)SignatureTypeCode.SZArray:
                elementType = DecodeType(ref blobReader, provider);
                return(provider.GetSZArrayType(elementType));

            case (int)SignatureTypeCode.FunctionPointer:
                MethodSignature <TType> methodSignature = DecodeMethodSignature(ref blobReader, provider);
                return(provider.GetFunctionPointerType(methodSignature));

            case (int)SignatureTypeCode.Array:
                return(DecodeArrayType(ref blobReader, provider));

            case (int)SignatureTypeCode.RequiredModifier:
                return(DecodeModifiedType(ref blobReader, provider, isRequired: true));

            case (int)SignatureTypeCode.OptionalModifier:
                return(DecodeModifiedType(ref blobReader, provider, isRequired: false));

            case (int)SignatureTypeCode.GenericTypeInstance:
                return(DecodeGenericTypeInstance(ref blobReader, provider));

            case (int)SignatureTypeCode.GenericTypeParameter:
                index = blobReader.ReadCompressedInteger();
                return(provider.GetGenericTypeParameter(index));

            case (int)SignatureTypeCode.GenericMethodParameter:
                index = blobReader.ReadCompressedInteger();
                return(provider.GetGenericMethodParameter(index));

            case 0x11:    //(int)CorElementType.ELEMENT_TYPE_CLASS
                return(DecodeTypeHandle(ref blobReader, provider, false));

            case 0x12:     //(int)CorElementType.ELEMENT_TYPE_VALUETYPE:
                return(DecodeTypeHandle(ref blobReader, provider, true));

            default:
                throw new BadImageFormatException();
            }
        }
Exemple #2
0
        private TType DecodeType(ref BlobReader blobReader, bool allowTypeSpecifications, int typeCode)
        {
            TType elementType;
            int   index;

            switch (typeCode)
            {
            case (int)SignatureTypeCode.Boolean:
            case (int)SignatureTypeCode.Char:
            case (int)SignatureTypeCode.SByte:
            case (int)SignatureTypeCode.Byte:
            case (int)SignatureTypeCode.Int16:
            case (int)SignatureTypeCode.UInt16:
            case (int)SignatureTypeCode.Int32:
            case (int)SignatureTypeCode.UInt32:
            case (int)SignatureTypeCode.Int64:
            case (int)SignatureTypeCode.UInt64:
            case (int)SignatureTypeCode.Single:
            case (int)SignatureTypeCode.Double:
            case (int)SignatureTypeCode.IntPtr:
            case (int)SignatureTypeCode.UIntPtr:
            case (int)SignatureTypeCode.Object:
            case (int)SignatureTypeCode.String:
            case (int)SignatureTypeCode.Void:
            case (int)SignatureTypeCode.TypedReference:
                return(_provider.GetPrimitiveType((PrimitiveTypeCode)typeCode));

            case (int)SignatureTypeCode.Pointer:
                elementType = DecodeType(ref blobReader);
                return(_provider.GetPointerType(elementType));

            case (int)SignatureTypeCode.ByReference:
                elementType = DecodeType(ref blobReader);
                return(_provider.GetByReferenceType(elementType));

            case (int)SignatureTypeCode.Pinned:
                elementType = DecodeType(ref blobReader);
                return(_provider.GetPinnedType(elementType));

            case (int)SignatureTypeCode.SZArray:
                elementType = DecodeType(ref blobReader);
                return(_provider.GetSZArrayType(elementType));

            case (int)SignatureTypeCode.FunctionPointer:
                MethodSignature <TType> methodSignature = DecodeMethodSignature(ref blobReader);
                return(_provider.GetFunctionPointerType(methodSignature));

            case (int)SignatureTypeCode.Array:
                return(DecodeArrayType(ref blobReader));

            case (int)SignatureTypeCode.RequiredModifier:
                return(DecodeModifiedType(ref blobReader, isRequired: true));

            case (int)SignatureTypeCode.OptionalModifier:
                return(DecodeModifiedType(ref blobReader, isRequired: false));

            case (int)SignatureTypeCode.GenericTypeInstance:
                return(DecodeGenericTypeInstance(ref blobReader));

            case (int)SignatureTypeCode.GenericTypeParameter:
                index = blobReader.ReadCompressedInteger();
                return(_provider.GetGenericTypeParameter(_genericContext, index));

            case (int)SignatureTypeCode.GenericMethodParameter:
                index = blobReader.ReadCompressedInteger();
                return(_provider.GetGenericMethodParameter(_genericContext, index));

            case (int)SignatureTypeKind.Class:
            case (int)SignatureTypeKind.ValueType:
                return(DecodeTypeHandle(ref blobReader, (byte)typeCode, allowTypeSpecifications));

            default:
                throw new BadImageFormatException(StarkPlatform.Reflection.Resources.SR.Format(SR.UnexpectedSignatureTypeCode, typeCode));
            }
        }
Exemple #3
0
 public RoType GetFunctionPointerType(MethodSignature <RoType> signature) => _typeProvider.GetFunctionPointerType(signature);