ReadFieldOrPropType() public static method

public static ReadFieldOrPropType ( MetadataHeader header, IBinaryStreamReader reader ) : TypeSignature
header MetadataHeader
reader IBinaryStreamReader
return TypeSignature
        public static CustomAttributeNamedArgument FromReader(MetadataImage image, IBinaryStreamReader reader)
        {
            var signature = new CustomAttributeNamedArgument
            {
                ArgumentMemberType =
                    (reader.CanRead(sizeof(byte))
                        ? (CustomAttributeArgumentMemberType)reader.ReadByte()
                        : CustomAttributeArgumentMemberType.Field),
                ArgumentType = TypeSignature.ReadFieldOrPropType(image, reader),
                MemberName   = reader.ReadSerString(),
            };

            signature.Argument = CustomAttributeArgument.FromReader(image, signature.ArgumentType, reader);
            return(signature);
        }
Example #2
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);
        }