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); }
public override void LoadCache() { _parent = Parent; _constructor = Constructor; _signature = Signature; }
public override void ClearCache() { _parent = null; _constructor = null; _signature = null; }
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; }