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. }
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; }
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; }