using System.Reflection.Metadata; using System.Reflection.PortableExecutable; var peStream = File.OpenRead("MyAssembly.dll"); var peReader = new PEReader(peStream); var metadataReader = peReader.GetMetadataReader(); var method = metadataReader.GetMethodDefinition(1); var signature = metadataReader.GetBlobReader(method.Signature); // Read the signature var opcode = signature.ReadBytes(1)[0];
using System.Reflection.Metadata; var blobReader = new BlobReader(new byte[] { 1, 2, 3, 4, 5 }); var data = blobReader.ReadBytes(blobReader.Length); Console.WriteLine(string.Join(",", data));This example creates a new instance of BlobReader and reads all the bytes from the blob using the ReadBytes method. Since the metadata blob is just a sequence of bytes, it can be read and manipulated like any other byte array. This code may exist in a package library like the System.Reflection.Metadata in .NET Core.