using System.Reflection.Metadata; using System.Reflection.PortableExecutable; namespace Test { class Program { static void Main(string[] args) { using (var peReader = new PEReader(File.OpenRead("TestAssembly.dll"))) { var metadataReader = peReader.GetMetadataReader(); var documentHandle = MetadataTokens.DocumentHandle(1); var document = metadataReader.GetDocument(documentHandle); var name = document.Name; var hashAlgorithm = document.HashAlgorithm; var language = document.Language; var checksum = document.Hash; // ... } } } }
using System; using System.Reflection; using System.Reflection.Metadata; using System.Reflection.PortableExecutable; class Program { static void Main(string[] args) { Assembly asm = Assembly.LoadFrom(@"TestAssembly.dll"); using (var stream = asm.GetManifestResourceStream("TestAssembly.g.manifest")) { using (var peReader = new PEReader(stream)) { var metadataReader = peReader.GetMetadataReader(); foreach (var documentHandle in metadataReader.Documents) { var document = metadataReader.GetDocument(documentHandle); Console.WriteLine($"Document name: {document.Name}"); } } } } }This example shows how to use the GetDocument method in combination with other MetadataReader methods to retrieve information about all documents in the assembly. Here we are retrieving all documents and printing their names. Package library: The MetadataReader class is a part of the System.Reflection.Metadata package in the .NET Framework.