FromAssemblyQualifiedName() public static method

public static FromAssemblyQualifiedName ( MetadataHeader header, string assemblyQualifiedName ) : TypeSignature
header MetadataHeader
assemblyQualifiedName string
return TypeSignature
Esempio n. 1
0
        private static object ReadValue(MetadataImage image, TypeSignature typeSignature, IBinaryStreamReader reader)
        {
            switch (typeSignature.ElementType)
            {
            case ElementType.Boolean:
                return(reader.ReadByte() == 1);

            case ElementType.Char:
                return((char)reader.ReadUInt16());

            case ElementType.R4:
                return(reader.ReadSingle());

            case ElementType.R8:
                return(reader.ReadDouble());

            case ElementType.I1:
                return(reader.ReadSByte());

            case ElementType.I2:
                return(reader.ReadInt16());

            case ElementType.I4:
                return(reader.ReadInt32());

            case ElementType.I8:
                return(reader.ReadInt64());

            case ElementType.U1:
                return(reader.ReadByte());

            case ElementType.U2:
                return(reader.ReadUInt16());

            case ElementType.U4:
                return(reader.ReadUInt32());

            case ElementType.U8:
                return(reader.ReadUInt64());

            case ElementType.String:
                return(reader.ReadSerString());

            case ElementType.Object:
                return(ReadValue(image, TypeSignature.ReadFieldOrPropType(image, reader), reader));

            case ElementType.Class:
            case ElementType.Enum:
            case ElementType.ValueType:
                var enumTypeDef = image.MetadataResolver.ResolveType(typeSignature);
                if (enumTypeDef == null)
                {
                    throw new MemberResolutionException(typeSignature);
                }

                if (enumTypeDef.IsEnum)
                {
                    return(ReadValue(image, enumTypeDef.GetEnumUnderlyingType(), reader));
                }
                break;
            }

            if (typeSignature.IsTypeOf("System", "Type"))
            {
                return(TypeSignature.FromAssemblyQualifiedName(image, reader.ReadSerString()));
            }

            throw new NotSupportedException("Unsupported element type " + typeSignature.ElementType);
        }