using System.Reflection.Metadata; using System.Reflection.PortableExecutable; // Open the assembly file using var stream = File.OpenRead("MyAssembly.dll"); // Read the metadata using var peReader = new PEReader(stream); var metadataReader = peReader.GetMetadataReader(); // Get the assembly name var assemblyName = metadataReader.GetString(metadataReader.GetAssemblyDefinition().Name);
using System.Reflection.Metadata; using System.Reflection.PortableExecutable; // Open the assembly file using var stream = File.OpenRead("MyAssembly.dll"); // Read the metadata using var peReader = new PEReader(stream); var metadataReader = peReader.GetMetadataReader(); // Get all methods in the assembly foreach (var methodHandle in metadataReader.MethodDefinitions) { var methodDefinition = metadataReader.GetMethodDefinition(methodHandle); var methodName = metadataReader.GetString(methodDefinition.Name); var methodAttributes = methodDefinition.Attributes; }In this example, the metadata reader is used to get all methods defined in the assembly. The method handle is used to retrieve the method definition, and then the name and attributes of the method are retrieved. The Internal.Metadata.NativeFormat MetadataReader is part of the .NET Core SDK and can be found in the System.Reflection.Metadata.dll package.