Esempio n. 1
0
        private object ReadArgumentValue(BlobSignatureReader reader, TypeReference paramType)
        {
            if (!paramType.IsArray || !(paramType as ArrayType).IsVector)
            {
                return(ReadElement(reader, paramType));
            }

            // throw new NotImplementedException("Array constructor values are not supported yet.");

            ushort elementcount = reader.ReadUInt16();

            object[] elements = new object[elementcount];
            for (int i = 0; i < elementcount; i++)
            {
                elements[i] = ReadElement(reader, (paramType as ArrayType).OriginalType);
            }

            return(elements);
        }
Esempio n. 2
0
        public CustomAttributeSignature ReadCustomAttributeSignature(CustomAttribute parent, uint signature)
        {
            CustomAttributeSignature customAttrSig = null;

            using (BlobSignatureReader reader = GetBlobReader(signature))
            {
                ushort sign = reader.ReadUInt16();
                if (sign != 0x0001)
                {
                    throw new ArgumentException("Signature doesn't refer to a valid Custom Attribute signature");
                }


                int fixedArgCount = 0;



                if (parent.Constructor.Signature != null && parent.Constructor.Signature.Parameters != null)
                {
                    fixedArgCount = parent.Constructor.Signature.Parameters.Length;
                }

                CustomAttributeArgument[] fixedArgs = new CustomAttributeArgument[fixedArgCount];


                for (int i = 0; i < fixedArgCount; i++)
                {
                    fixedArgs[i] = new CustomAttributeArgument(ReadArgumentValue(reader, parent.Constructor.Signature.Parameters[i].ParameterType));
                }

                int namedArgCount = 0;
                CustomAttributeArgument[] namedArgs = new CustomAttributeArgument[namedArgCount];

                customAttrSig = new CustomAttributeSignature(fixedArgs, namedArgs);
            }
            return(customAttrSig);
        }
Esempio n. 3
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);
        }