MetadataReader Class
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Reads metadata as defined by the ECMA 335 CLI specification.
public ref class MetadataReader sealed
public sealed class MetadataReader
type MetadataReader = class
Public NotInheritable Class MetadataReader
- Inheritance
-
MetadataReader
Examples
This example shows how to create MetadataReader for an assembly and read all type definitions from it:
using var fs = new FileStream("Example.dll", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
using var peReader = new PEReader(fs);
MetadataReader mr = peReader.GetMetadataReader();
foreach (TypeDefinitionHandle tdefh in mr.TypeDefinitions)
{
TypeDefinition tdef = mr.GetTypeDefinition(tdefh);
string ns = mr.GetString(tdef.Namespace);
string name = mr.GetString(tdef.Name);
Console.WriteLine($"{ns}.{name}");
}
Remarks
MetadataReader reads the contents of tables and heaps from the specified CLI metadata. It operates low-level constructs such as type and method definitions. For a higher level API to inspect the contents of assemblies using reflection constructs, see MetadataLoadContext.
You can use constructors, such as MetadataReader(Byte*, Int32), to create an instance of MetadataReader for a given memory location. To read metadata from the Portable Executable assembly file, create PEReader and use the GetMetadataReader(PEReader) extension method.
The format of CLI metadata is defined by the ECMA-335 specification. For more information, see Standard ECMA-335 - Common Language Infrastructure (CLI) on the Ecma International Web site.
Constructors
MetadataReader(Byte*, Int32) |
Initializes a new instance of the MetadataReader class from the metadata stored at the given memory location. |
MetadataReader(Byte*, Int32, MetadataReaderOptions) |
Initializes a new instance of the MetadataReader class from the metadata stored at the given memory location. |
MetadataReader(Byte*, Int32, MetadataReaderOptions, MetadataStringDecoder) |
Initializes a new instance of the MetadataReader class from the metadata stored at the given memory location. |
Properties
AssemblyFiles | |
AssemblyReferences | |
CustomAttributes | |
CustomDebugInformation | |
DebugMetadataHeader |
Gets the information decoded from #Pdb stream, or |
DeclarativeSecurityAttributes | |
Documents | |
EventDefinitions | |
ExportedTypes | |
FieldDefinitions | |
ImportScopes | |
IsAssembly |
Gets a value that indicates whether the metadata represents an assembly. |
LocalConstants | |
LocalScopes | |
LocalVariables | |
ManifestResources | |
MemberReferences | |
MetadataKind |
Gets the metadata kind. |
MetadataLength |
Gets the length of the underlying data. |
MetadataPointer |
Gets the pointer to the underlying data. |
MetadataVersion |
Gets the version string read from metadata header. |
MethodDebugInformation | |
MethodDefinitions | |
Options |
Gets the MetadataReaderOptions passed to the constructor. |
PropertyDefinitions | |
StringComparer |
Gets the comparer used to compare strings stored in metadata. |
TypeDefinitions | |
TypeReferences | |
UTF8Decoder |
Gets the decoder used by the reader to produce string instances from UTF8-encoded byte sequences. |
Methods
Extension Methods
GetEditAndContinueLogEntries(MetadataReader) |
Enumerates entries of EnC log. |
GetEditAndContinueMapEntries(MetadataReader) |
Enumerates entries of EnC map. |
GetHeapMetadataOffset(MetadataReader, HeapIndex) |
Returns the offset from the start of metadata to the specified heap. |
GetHeapSize(MetadataReader, HeapIndex) |
Returns the size of the specified heap. |
GetNextHandle(MetadataReader, BlobHandle) |
Returns the handle to the Blob that follows the given one in the Blob heap or a nil handle if it is the last one. |
GetNextHandle(MetadataReader, StringHandle) |
Returns the a handle to the string that follows the given one in the string heap, or a nil handle if it is the last one. |
GetNextHandle(MetadataReader, UserStringHandle) |
Returns the a handle to the UserString that follows the given one in the UserString heap or a nil handle if it is the last one. |
GetTableMetadataOffset(MetadataReader, TableIndex) |
Returns the offset from the start of metadata to the specified table. |
GetTableRowCount(MetadataReader, TableIndex) |
Returns the number of rows in the specified table. |
GetTableRowSize(MetadataReader, TableIndex) |
Returns the size of a row in the specified table. |
GetTypesWithEvents(MetadataReader) |
Enumerate types that define one or more events. |
GetTypesWithProperties(MetadataReader) |
Enumerate types that define one or more properties. |
ResolveSignatureTypeKind(MetadataReader, EntityHandle, Byte) |
Given a type handle and a raw type kind found in a signature blob determines whether the target type is a value type or a reference type. |
GetHeapOffset(MetadataReader, Handle) |
Gets the offset of metadata heap data that corresponds to the specified |
GetRowNumber(MetadataReader, EntityHandle) |
Gets the row number of a metadata table entry that corresponds to the specified |
GetToken(MetadataReader, EntityHandle) |
Gets the metadata token of the specified |
GetToken(MetadataReader, Handle) |
Gets the metadata token of the specified |