MetadataReader 類別

定義

如 ECMA 335 CLI 規格所定義,讀取中繼資料。

public ref class MetadataReader sealed
public sealed class MetadataReader
type MetadataReader = class
Public NotInheritable Class MetadataReader
繼承
MetadataReader

範例

此範例示範如何為元件建立 MetadataReader ,並從中讀取所有類型定義:

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}");
}

備註

MetadataReader 從指定的 CLI 中繼資料讀取資料表和堆積的內容。 它會操作低階建構,例如型別和方法定義。 如需使用反映建構檢查元件內容的較高層級 API,請參閱 MetadataLoadContext

您可以使用 建構函式,例如 MetadataReader(Byte*, Int32) ,為指定的記憶體位置建立 的 MetadataReader 實例。 若要從可攜式可執行檔元件檔讀取中繼資料,請建立 PEReader 並使用 GetMetadataReader(PEReader) 擴充方法。

CLI 中繼資料的格式是由 ECMA-335 規格所定義。 如需詳細資訊,請參閱 Ecma International 網站上的 標準 ECMA-335 - Common Language Infrastructure (CLI)

建構函式

MetadataReader(Byte*, Int32)

從儲存在給定記憶體位置的中繼資料,初始化 MetadataReader 類別的新執行個體。

MetadataReader(Byte*, Int32, MetadataReaderOptions)

從儲存在給定記憶體位置的中繼資料,初始化 MetadataReader 類別的新執行個體。

MetadataReader(Byte*, Int32, MetadataReaderOptions, MetadataStringDecoder)

從儲存在給定記憶體位置的中繼資料,初始化 MetadataReader 類別的新執行個體。

屬性

AssemblyFiles

如 ECMA 335 CLI 規格所定義,讀取中繼資料。

AssemblyReferences

如 ECMA 335 CLI 規格所定義,讀取中繼資料。

CustomAttributes

如 ECMA 335 CLI 規格所定義,讀取中繼資料。

CustomDebugInformation

如 ECMA 335 CLI 規格所定義,讀取中繼資料。

DebugMetadataHeader

從 #Pdb 資料流取得已解碼資訊,如果資料流不存在則為 null

DeclarativeSecurityAttributes

如 ECMA 335 CLI 規格所定義,讀取中繼資料。

Documents

如 ECMA 335 CLI 規格所定義,讀取中繼資料。

EventDefinitions

如 ECMA 335 CLI 規格所定義,讀取中繼資料。

ExportedTypes

如 ECMA 335 CLI 規格所定義,讀取中繼資料。

FieldDefinitions

如 ECMA 335 CLI 規格所定義,讀取中繼資料。

ImportScopes

如 ECMA 335 CLI 規格所定義,讀取中繼資料。

IsAssembly

取得值,這個值表示中繼資料是否代表組件。

LocalConstants

如 ECMA 335 CLI 規格所定義,讀取中繼資料。

LocalScopes

如 ECMA 335 CLI 規格所定義,讀取中繼資料。

LocalVariables

如 ECMA 335 CLI 規格所定義,讀取中繼資料。

ManifestResources

如 ECMA 335 CLI 規格所定義,讀取中繼資料。

MemberReferences

如 ECMA 335 CLI 規格所定義,讀取中繼資料。

MetadataKind

取得中繼資料類型。

MetadataLength

取得基礎資料的長度。

MetadataPointer

取得基礎資料的指標。

MetadataVersion

取得從中繼資料標頭讀取的版本字串。

MethodDebugInformation

如 ECMA 335 CLI 規格所定義,讀取中繼資料。

MethodDefinitions

如 ECMA 335 CLI 規格所定義,讀取中繼資料。

Options

取得傳遞至建構函式的 MetadataReaderOptions

PropertyDefinitions

如 ECMA 335 CLI 規格所定義,讀取中繼資料。

StringComparer

取得用來比較儲存在中繼資料中之字串的比較子。

TypeDefinitions

如 ECMA 335 CLI 規格所定義,讀取中繼資料。

TypeReferences

如 ECMA 335 CLI 規格所定義,讀取中繼資料。

UTF8Decoder

取得讀取器用來從 UTF8 編碼位元組序列產生字串執行個體的解碼器。

方法

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetAssemblyDefinition()

如 ECMA 335 CLI 規格所定義,讀取中繼資料。

GetAssemblyFile(AssemblyFileHandle)

如 ECMA 335 CLI 規格所定義,讀取中繼資料。

GetAssemblyName(String)

取得指定檔案的 AssemblyName

GetAssemblyReference(AssemblyReferenceHandle)

如 ECMA 335 CLI 規格所定義,讀取中繼資料。

GetBlobBytes(BlobHandle)

如 ECMA 335 CLI 規格所定義,讀取中繼資料。

GetBlobContent(BlobHandle)

如 ECMA 335 CLI 規格所定義,讀取中繼資料。

GetBlobReader(BlobHandle)

如 ECMA 335 CLI 規格所定義,讀取中繼資料。

GetBlobReader(StringHandle)

如 ECMA 335 CLI 規格所定義,讀取中繼資料。

GetConstant(ConstantHandle)

如 ECMA 335 CLI 規格所定義,讀取中繼資料。

GetCustomAttribute(CustomAttributeHandle)

如 ECMA 335 CLI 規格所定義,讀取中繼資料。

GetCustomAttributes(EntityHandle)

如 ECMA 335 CLI 規格所定義,讀取中繼資料。

GetCustomDebugInformation(CustomDebugInformationHandle)

如 ECMA 335 CLI 規格所定義,讀取中繼資料。

GetCustomDebugInformation(EntityHandle)

如 ECMA 335 CLI 規格所定義,讀取中繼資料。

GetDeclarativeSecurityAttribute(DeclarativeSecurityAttributeHandle)

如 ECMA 335 CLI 規格所定義,讀取中繼資料。

GetDocument(DocumentHandle)

如 ECMA 335 CLI 規格所定義,讀取中繼資料。

GetEventDefinition(EventDefinitionHandle)

如 ECMA 335 CLI 規格所定義,讀取中繼資料。

GetExportedType(ExportedTypeHandle)

如 ECMA 335 CLI 規格所定義,讀取中繼資料。

GetFieldDefinition(FieldDefinitionHandle)

如 ECMA 335 CLI 規格所定義,讀取中繼資料。

GetGenericParameter(GenericParameterHandle)

如 ECMA 335 CLI 規格所定義,讀取中繼資料。

GetGenericParameterConstraint(GenericParameterConstraintHandle)

如 ECMA 335 CLI 規格所定義,讀取中繼資料。

GetGuid(GuidHandle)

如 ECMA 335 CLI 規格所定義,讀取中繼資料。

GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetImportScope(ImportScopeHandle)

如 ECMA 335 CLI 規格所定義,讀取中繼資料。

GetInterfaceImplementation(InterfaceImplementationHandle)

如 ECMA 335 CLI 規格所定義,讀取中繼資料。

GetLocalConstant(LocalConstantHandle)

如 ECMA 335 CLI 規格所定義,讀取中繼資料。

GetLocalScope(LocalScopeHandle)

如 ECMA 335 CLI 規格所定義,讀取中繼資料。

GetLocalScopes(MethodDebugInformationHandle)

如 ECMA 335 CLI 規格所定義,讀取中繼資料。

GetLocalScopes(MethodDefinitionHandle)

如 ECMA 335 CLI 規格所定義,讀取中繼資料。

GetLocalVariable(LocalVariableHandle)

如 ECMA 335 CLI 規格所定義,讀取中繼資料。

GetManifestResource(ManifestResourceHandle)

如 ECMA 335 CLI 規格所定義,讀取中繼資料。

GetMemberReference(MemberReferenceHandle)

如 ECMA 335 CLI 規格所定義,讀取中繼資料。

GetMethodDebugInformation(MethodDebugInformationHandle)

如 ECMA 335 CLI 規格所定義,讀取中繼資料。

GetMethodDebugInformation(MethodDefinitionHandle)

如 ECMA 335 CLI 規格所定義,讀取中繼資料。

GetMethodDefinition(MethodDefinitionHandle)

如 ECMA 335 CLI 規格所定義,讀取中繼資料。

GetMethodImplementation(MethodImplementationHandle)

如 ECMA 335 CLI 規格所定義,讀取中繼資料。

GetMethodSpecification(MethodSpecificationHandle)

如 ECMA 335 CLI 規格所定義,讀取中繼資料。

GetModuleDefinition()

如 ECMA 335 CLI 規格所定義,讀取中繼資料。

GetModuleReference(ModuleReferenceHandle)

如 ECMA 335 CLI 規格所定義,讀取中繼資料。

GetNamespaceDefinition(NamespaceDefinitionHandle)

如 ECMA 335 CLI 規格所定義,讀取中繼資料。

GetNamespaceDefinitionRoot()

如 ECMA 335 CLI 規格所定義,讀取中繼資料。

GetParameter(ParameterHandle)

如 ECMA 335 CLI 規格所定義,讀取中繼資料。

GetPropertyDefinition(PropertyDefinitionHandle)

如 ECMA 335 CLI 規格所定義,讀取中繼資料。

GetStandaloneSignature(StandaloneSignatureHandle)

如 ECMA 335 CLI 規格所定義,讀取中繼資料。

GetString(DocumentNameBlobHandle)

如 ECMA 335 CLI 規格所定義,讀取中繼資料。

GetString(NamespaceDefinitionHandle)

如 ECMA 335 CLI 規格所定義,讀取中繼資料。

GetString(StringHandle)

如 ECMA 335 CLI 規格所定義,讀取中繼資料。

GetType()

取得目前執行個體的 Type

(繼承來源 Object)
GetTypeDefinition(TypeDefinitionHandle)

如 ECMA 335 CLI 規格所定義,讀取中繼資料。

GetTypeReference(TypeReferenceHandle)

如 ECMA 335 CLI 規格所定義,讀取中繼資料。

GetTypeSpecification(TypeSpecificationHandle)

如 ECMA 335 CLI 規格所定義,讀取中繼資料。

GetUserString(UserStringHandle)

如 ECMA 335 CLI 規格所定義,讀取中繼資料。

MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

擴充方法

GetEditAndContinueLogEntries(MetadataReader)

列舉 EnC 記錄的項目。

GetEditAndContinueMapEntries(MetadataReader)

列舉 EnC 對應的項目。

GetHeapMetadataOffset(MetadataReader, HeapIndex)

傳回從中繼資料開頭到指定堆積的位移。

GetHeapSize(MetadataReader, HeapIndex)

傳回指定堆積的大小。

GetNextHandle(MetadataReader, BlobHandle)

傳回 Blob 的控制代碼,該控制代碼會位在 Blob 堆積中所提供項目之後,或若其為最後一個項目,則為 Nil 控制代碼。

GetNextHandle(MetadataReader, StringHandle)

傳回字串的控制代碼,該控制代碼會位在字串堆積中所提供項目之後,或若其為最後一個項目,則為 Nil 控制代碼。

GetNextHandle(MetadataReader, UserStringHandle)

傳回 UserString 的控制代碼,該控制代碼會位在 UserString 堆積中所提供項目之後,或若其為最後一個項目,則為 Nil 控制代碼。

GetTableMetadataOffset(MetadataReader, TableIndex)

傳回從中繼資料開頭到指定資料表的位移。

GetTableRowCount(MetadataReader, TableIndex)

傳回指定資料表中的資料列數。

GetTableRowSize(MetadataReader, TableIndex)

傳回指定資料表中的資料列大小。

GetTypesWithEvents(MetadataReader)

列舉定義一或多個事件的類型。

GetTypesWithProperties(MetadataReader)

列舉定義一或多個屬性的類型。

ResolveSignatureTypeKind(MetadataReader, EntityHandle, Byte)

簽章 Blob 中找到的類型控制代碼和原始類型種類會決定目標類型為實值型別還是參考型別。

GetHeapOffset(MetadataReader, Handle)

取得中繼資料堆積資料的位移,該中繼資料對應至 reader 內容中的指定 handle

GetRowNumber(MetadataReader, EntityHandle)

取得對應至 reader 內容中指定 handle 之中繼資料資料表項目的資料列號碼。

GetToken(MetadataReader, EntityHandle)

取得 reader 內容中指定 handle 的中繼資料權杖。

GetToken(MetadataReader, Handle)

取得 reader 內容中指定 handle 的中繼資料權杖。

適用於