コード例 #1
0
        internal CustomAttrib.NamedArg ReadNamedArg(byte [] data, BinaryReader br, ref bool read, bool resolve)
        {
            CustomAttrib.NamedArg na = new CustomAttrib.NamedArg();
            byte kind = br.ReadByte();

            if (kind == 0x53)               // field
            {
                na.Field    = true;
                na.Property = false;
            }
            else if (kind == 0x54)                 // property
            {
                na.Field    = false;
                na.Property = true;
            }
            else
            {
                throw new MetadataFormatException("Wrong kind of namedarg found: 0x" + kind.ToString("x2"));
            }

            TypeReference elemType = ReadTypeReference(data, br, out na.FieldOrPropType);

            na.FieldOrPropName = ReadUTF8String(data, br);
            na.FixedArg        = ReadFixedArg(data, br, elemType, ref read, resolve);

            return(na);
        }
コード例 #2
0
        void Write(CustomAttrib.NamedArg na, MemoryBinaryWriter writer)
        {
            if (na.Field)
            {
                writer.Write((byte)0x53);
            }
            else if (na.Property)
            {
                writer.Write((byte)0x54);
            }
            else
            {
                throw new MetadataFormatException("Unknown kind of namedarg");
            }

            if (na.FieldOrPropType == ElementType.Class)
            {
                na.FieldOrPropType = ElementType.Enum;
            }

            if (na.FixedArg.SzArray)
            {
                writer.Write((byte)ElementType.SzArray);
            }

            if (na.FieldOrPropType == ElementType.Object)
            {
                writer.Write((byte)ElementType.Boxed);
            }
            else
            {
                writer.Write((byte)na.FieldOrPropType);
            }

            if (na.FieldOrPropType == ElementType.Enum)
            {
                Write(GetEnumFullName(na.FixedArg.Elems [0].ElemType));
            }

            Write(na.FieldOrPropName);

            Write(na.FixedArg, writer);
        }