using System.Reflection.Metadata; using System.Reflection.Metadata.Ecma335; var module = ModuleMetadata.CreateFromStream(stream); // a stream containing the module's metadata var reader = module.MetadataReader; foreach(var methodHandle in reader.MethodDefinitions) { var method = reader.GetMethodDefinition(methodHandle); foreach(var customAttributeHandle in method.GetCustomAttributes()) { var customAttribute = reader.GetCustomAttribute(customAttributeHandle); var blob = reader.GetBlobBytes(customAttribute.Value); // do something with the blob data } }
using System.Reflection.Metadata; var module = ModuleMetadata.CreateFromStream(stream); // a stream containing the module's metadata var reader = module.MetadataReader; var field = reader.GetFieldDefinition(fieldHandle); var type = reader.GetTypeDefinition(field.GetDeclaringType()); var fieldType = reader.GetTypeSpecification(type.GetFieldType()); var blob = reader.GetBlobBytes(fieldType.Signature); // do something with the blob dataThis example shows how you can use GetBlobBytes to retrieve the signature of a field in a .NET assembly. We first use GetFieldDefinition to get the field metadata, then use GetTypeDefinition to get the declaring type metadata. We can then use GetFieldType to get the type specification for the field, which contains the signature data that we can retrieve using GetBlobBytes. Package Library: System.Reflection.Metadata.dll