상속: MetaDataMember
예제 #1
0
 private void UpdateCustomAttribute(Workspace workspace, CustomAttribute customAttribute)
 {
     customAttribute.MetaDataRow.Parts[0] = GetMemberIndex(workspace, Constructor.OriginalAssembly.NETHeader.TablesHeap.HasCustomAttribute, customAttribute.Parent);
     customAttribute.MetaDataRow.Parts[1] = GetMemberIndex(workspace, Constructor.OriginalAssembly.NETHeader.TablesHeap.CustomAttributeType, customAttribute.Constructor);
     // TODO: serialize blob.
 }
예제 #2
0
        public CustomAttributeSignature ReadCustomAttributeSignature(CustomAttribute parent, uint signature)
        {
            CustomAttributeSignature customAttrSig = null;
            using (BinaryReader 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;
        }
예제 #3
0
파일: BlobHeap.cs 프로젝트: Rex-Hays/GNIDA
        public CustomAttributeSignature ReadCustomAttributeSignature(CustomAttribute parent, uint signature)
        {
            CustomAttributeSignature customAttrSig = null;
            BlobSignatureReader reader;
            if (TryGetBlobReader(signature, out reader))
            {
                using (reader)
                {
                    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];
                    bool canReadNamedArgs = true; // temporary solution for skipping named args when fixed args failed.
                    for (int i = 0; i < fixedArgCount; i++)
                    {
                        fixedArgs[i] = new CustomAttributeArgument(reader.ReadCustomAttributeArgumentValue(parent.Constructor.Signature.Parameters[i].ParameterType));
                        if (fixedArgs[i].Value == null)
                            canReadNamedArgs = false;
                    }

                    CustomAttributeArgument[] namedArgs = null;
                    if (!reader.EndOfStream && canReadNamedArgs)
                    {
                        int namedArgCount = reader.ReadUInt16();
                        namedArgs = new CustomAttributeArgument[namedArgCount];

                        for (int i = 0; i < namedArgCount; i++)
                        {
                            byte argSignature = reader.ReadByte();
                            TypeReference argType = reader.ReadCustomAttributeFieldOrPropType();
                            string name = reader.ReadUtf8String();
                            namedArgs[i] = new CustomAttributeArgument(reader.ReadCustomAttributeArgumentValue(argType), name, argSignature == 0x53 ? CustomAttributeArgumentType.NamedField : CustomAttributeArgumentType.NamedProperty);
                        }
                    }

                    customAttrSig = new CustomAttributeSignature(fixedArgs, namedArgs);
                }
            }
            return customAttrSig;
        }