/// <summary> /// Reads custom attribute named arguments /// </summary> /// <param name="module">Owner module</param> /// <param name="stream">A stream positioned at the the first byte of the CA blob</param> /// <param name="numNamedArgs">Number of named arguments to read from <paramref name="stream"/></param> /// <param name="gpContext">Generic parameter context</param> /// <returns>A list of <see cref="CANamedArgument"/>s or <c>null</c> if some error /// occurred.</returns> internal static List <CANamedArgument> ReadNamedArguments(ModuleDef module, IBinaryReader stream, int numNamedArgs, GenericParamContext gpContext) { try { using (var reader = new CustomAttributeReader(module, stream, false, gpContext)) return(reader.ReadNamedArguments(numNamedArgs)); } catch (CABlobParserException) { return(null); } catch (IOException) { return(null); } }
/// <summary> /// Reads the new (.NET 2.0+) DeclSecurity blob format /// </summary> /// <returns></returns> private ThreadSafe.IList <SecurityAttribute> ReadBinaryFormat() { int numAttrs = (int)reader.ReadCompressedUInt32(); var list = ThreadSafeListCreator.Create <SecurityAttribute>(numAttrs); for (int i = 0; i < numAttrs; i++) { var name = ReadUTF8String(); // Use CA search rules. Some tools don't write the fully qualified name. var attrRef = TypeNameParser.ParseReflection(module, UTF8String.ToSystemStringOrEmpty(name), new CAAssemblyRefFinder(module), gpContext); int blobLength = (int)reader.ReadCompressedUInt32(); int numNamedArgs = (int)reader.ReadCompressedUInt32(); var namedArgs = CustomAttributeReader.ReadNamedArguments(module, reader, numNamedArgs, gpContext); if (namedArgs == null) { throw new ApplicationException("Could not read named arguments"); } list.Add(new SecurityAttribute(attrRef, namedArgs)); } return(list); }
/// <summary> /// Reads a custom attribute /// </summary> /// <param name="module">Owner module</param> /// <param name="stream">A stream positioned at the the first byte of the CA blob</param> /// <param name="ctor">Custom attribute constructor</param> /// <param name="gpContext">Generic parameter context</param> /// <returns>A new <see cref="CustomAttribute"/> instance</returns> public static CustomAttribute Read(ModuleDef module, IBinaryReader stream, ICustomAttributeType ctor, GenericParamContext gpContext) { using (var reader = new CustomAttributeReader(module, stream, gpContext)) { try { if (stream == null || ctor == null) { return(reader.CreateRaw(ctor)); } return(reader.Read(ctor)); } catch (CABlobParserException) { return(reader.CreateRaw(ctor)); } catch (IOException) { return(reader.CreateRaw(ctor)); } } }
/// <summary> /// Reads a custom attribute /// </summary> /// <param name="readerModule">Reader module</param> /// <param name="ctor">Custom attribute constructor</param> /// <param name="offset">Offset of custom attribute in the #Blob stream</param> /// <param name="gpContext">Generic parameter context</param> /// <returns>A new <see cref="CustomAttribute"/> instance</returns> public static CustomAttribute Read(ModuleDefMD readerModule, ICustomAttributeType ctor, uint offset, GenericParamContext gpContext) { using (var reader = new CustomAttributeReader(readerModule, offset, gpContext)) { try { if (ctor == null) { return(reader.CreateRaw(ctor)); } return(reader.Read(ctor)); } catch (CABlobParserException) { return(reader.CreateRaw(ctor)); } catch (IOException) { return(reader.CreateRaw(ctor)); } } }