Esempio n. 1
0
        private object ReadElement(BlobSignatureReader reader, TypeReference paramType)
        {
            switch (paramType.elementType)
            {
            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.ReadInt16());

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

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

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

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

            case ElementType.Type:
            case ElementType.String:
                uint size = NETGlobals.ReadCompressedUInt32(reader);
                if (size == 0xFF)
                {
                    return(string.Empty);
                }
                byte[] rawdata = reader.ReadBytes((int)size);
                return(Encoding.UTF8.GetString(rawdata));

            case ElementType.Char:
                return(reader.ReadChar());

                throw new NotSupportedException();

            case ElementType.Boolean:
                return(reader.ReadByte() == 1);
            }
            return(null);
        }
Esempio n. 2
0
        public object ReadConstantValue(ElementType type, uint signature)
        {
            object value = null;

            using (BlobSignatureReader reader = GetBlobReader(signature))
            {
                switch (type)
                {
                case ElementType.Boolean:
                    value = reader.ReadByte() == 1;
                    break;

                case ElementType.Char:
                    value = (char)reader.ReadUInt16();
                    break;

                case ElementType.String:
                    value = Encoding.Unicode.GetString(reader.ReadBytes((int)reader.BaseStream.Length));
                    break;

                case ElementType.I1:
                    value = reader.ReadSByte();
                    break;

                case ElementType.I2:
                    value = reader.ReadInt16();
                    break;

                case ElementType.I4:
                    value = reader.ReadInt32();
                    break;

                case ElementType.I8:
                    value = reader.ReadInt64();
                    break;

                case ElementType.U1:
                    value = reader.ReadByte();
                    break;

                case ElementType.U2:
                    value = reader.ReadUInt16();
                    break;

                case ElementType.U4:
                    value = reader.ReadUInt32();
                    break;

                case ElementType.U8:
                    value = reader.ReadUInt64();
                    break;

                case ElementType.R4:
                    value = reader.ReadSingle();
                    break;

                case ElementType.R8:
                    value = reader.ReadDouble();
                    break;

                default:
                    throw new ArgumentException("Invalid constant type", "type");
                }
            }
            return(value);
        }