Επεξεργασία

Κοινή χρήση μέσω


MetadataReader Class

Definition

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, MetadataReaderOptions, MetadataStringDecoder)

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)

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 null if the stream is not present.

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

Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetAssemblyDefinition()
GetAssemblyFile(AssemblyFileHandle)
GetAssemblyName(String)

Gets the AssemblyName for a given file.

GetAssemblyReference(AssemblyReferenceHandle)
GetBlobBytes(BlobHandle)
GetBlobContent(BlobHandle)
GetBlobReader(BlobHandle)
GetBlobReader(StringHandle)
GetConstant(ConstantHandle)
GetCustomAttribute(CustomAttributeHandle)
GetCustomAttributes(EntityHandle)
GetCustomDebugInformation(CustomDebugInformationHandle)
GetCustomDebugInformation(EntityHandle)
GetDeclarativeSecurityAttribute(DeclarativeSecurityAttributeHandle)
GetDocument(DocumentHandle)
GetEventDefinition(EventDefinitionHandle)
GetExportedType(ExportedTypeHandle)
GetFieldDefinition(FieldDefinitionHandle)
GetGenericParameter(GenericParameterHandle)
GetGenericParameterConstraint(GenericParameterConstraintHandle)
GetGuid(GuidHandle)
GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetImportScope(ImportScopeHandle)
GetInterfaceImplementation(InterfaceImplementationHandle)
GetLocalConstant(LocalConstantHandle)
GetLocalScope(LocalScopeHandle)
GetLocalScopes(MethodDebugInformationHandle)
GetLocalScopes(MethodDefinitionHandle)
GetLocalVariable(LocalVariableHandle)
GetManifestResource(ManifestResourceHandle)
GetMemberReference(MemberReferenceHandle)
GetMethodDebugInformation(MethodDebugInformationHandle)
GetMethodDebugInformation(MethodDefinitionHandle)
GetMethodDefinition(MethodDefinitionHandle)
GetMethodImplementation(MethodImplementationHandle)
GetMethodSpecification(MethodSpecificationHandle)
GetModuleDefinition()
GetModuleReference(ModuleReferenceHandle)
GetNamespaceDefinition(NamespaceDefinitionHandle)
GetNamespaceDefinitionRoot()
GetParameter(ParameterHandle)
GetPropertyDefinition(PropertyDefinitionHandle)
GetStandaloneSignature(StandaloneSignatureHandle)
GetString(DocumentNameBlobHandle)
GetString(NamespaceDefinitionHandle)
GetString(StringHandle)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
GetTypeDefinition(TypeDefinitionHandle)
GetTypeReference(TypeReferenceHandle)
GetTypeSpecification(TypeSpecificationHandle)
GetUserString(UserStringHandle)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
ToString()

Returns a string that represents the current object.

(Inherited from Object)

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 handle in the context of reader.

GetRowNumber(MetadataReader, EntityHandle)

Gets the row number of a metadata table entry that corresponds to the specified handle in the context of reader.

GetToken(MetadataReader, EntityHandle)

Gets the metadata token of the specified handle in the context of reader.

GetToken(MetadataReader, Handle)

Gets the metadata token of the specified handle in the context of reader.

Applies to