Class DotNetDirectoryBuffer
- Namespace
- AsmResolver.DotNet.Builder
- Assembly
- AsmResolver.DotNet.dll
Provides a mutable buffer for building up a .NET data directory, containing all metadata relevant for the execution of a .NET assembly.
public class DotNetDirectoryBuffer : ITypeCodedIndexProvider, IMetadataTokenProvider
- Inheritance
-
DotNetDirectoryBuffer
- Implements
- Inherited Members
Constructors
DotNetDirectoryBuffer(ModuleDefinition, IMethodBodySerializer, INativeSymbolsProvider, IMetadataBuffer, IErrorListener)
Creates a new .NET data directory buffer.
public DotNetDirectoryBuffer(ModuleDefinition module, IMethodBodySerializer methodBodySerializer, INativeSymbolsProvider symbolsProvider, IMetadataBuffer metadata, IErrorListener errorListener)
Parameters
moduleModuleDefinitionThe module for which this .NET directory is built.
methodBodySerializerIMethodBodySerializerThe method body serializer to use for constructing method bodies.
symbolsProviderINativeSymbolsProviderThe object responsible for providing references to native symbols.
metadataIMetadataBufferThe metadata builder
errorListenerIErrorListenerThe object responsible for collecting all diagnostic information during the building process.
Properties
ErrorListener
Gets the object responsible for collecting all diagnostic information during the building process.
public IErrorListener ErrorListener { get; }
Property Value
Metadata
Gets the metadata directory buffer, containing the metadata stream buffers.
public IMetadataBuffer Metadata { get; }
Property Value
MethodBodySerializer
Gets the method body serializer to use for constructing method bodies.
public IMethodBodySerializer MethodBodySerializer { get; }
Property Value
Module
Gets the module for which this .NET directory is built.
public ModuleDefinition Module { get; }
Property Value
Resources
Gets the .NET resources data directory buffer, containing all the resources data stored in the .NET module.
public DotNetResourcesDirectoryBuffer Resources { get; }
Property Value
StrongNameSize
Gets or sets the size of the strong name directory to be emitted. A value of 0 indicates no strong name directory will be emitted.
public int StrongNameSize { get; set; }
Property Value
SymbolsProvider
Gets the object responsible for providing references to native symbols.
public INativeSymbolsProvider SymbolsProvider { get; }
Property Value
VTableFixups
Gets the buffer used to store VTable fixups and register unmanaged symbols.
public VTableFixupsBuffer VTableFixups { get; }
Property Value
Methods
AddAssemblyReference(AssemblyReference?, bool, bool, object?)
Adds an assembly reference to the buffer.
public MetadataToken AddAssemblyReference(AssemblyReference? assembly, bool allowDuplicates, bool preserveRid, object? diagnosticSource = null)
Parameters
assemblyAssemblyReferenceThe reference to add.
allowDuplicatesbooltrueif the row is always to be added to the end of the buffer,falseif a duplicated row is supposed to be removed and the token of the original should be returned instead.preserveRidbooltrueif the metadata token of the assembly should be preserved,falseotherwise.diagnosticSourceobjectThe object that referenced the assembly.
Returns
- MetadataToken
The newly assigned metadata token.
AddMemberReference(MemberReference?, bool, object?)
Adds a member reference to the buffer.
public MetadataToken AddMemberReference(MemberReference? member, bool allowDuplicates, object? diagnosticSource = null)
Parameters
memberMemberReferenceThe reference to add.
allowDuplicatesbooltrueif the row is always to be added to the end of the buffer,falseif a duplicated row is supposed to be removed and the token of the original should be returned instead.diagnosticSourceobjectThe object that referenced the member.
Returns
- MetadataToken
The newly assigned metadata token.
AddMethodSpecification(MethodSpecification?, bool, object?)
Adds a method specification to the buffer.
public MetadataToken AddMethodSpecification(MethodSpecification? method, bool allowDuplicates, object? diagnosticSource = null)
Parameters
methodMethodSpecificationThe specification to add.
allowDuplicatesbooltrueif the row is always to be added to the end of the buffer,falseif a duplicated row is supposed to be removed and the token of the original should be returned instead.diagnosticSourceobjectThe object that referenced the method specification.
Returns
- MetadataToken
The newly assigned metadata token.
AddModuleReference(ModuleReference?, bool, bool, object?)
Adds a module reference to the buffer.
public MetadataToken AddModuleReference(ModuleReference? module, bool allowDuplicates, bool preserveRid, object? diagnosticSource = null)
Parameters
moduleModuleReferenceThe reference to add.
allowDuplicatesbooltrueif the row is always to be added to the end of the buffer,falseif a duplicated row is supposed to be removed and the token of the original should be returned instead.preserveRidbooltrueif the metadata token of the module should be preserved,falseotherwise.diagnosticSourceobjectThe object that referenced the module.
Returns
- MetadataToken
The newly assigned metadata token.
AddStandAloneSignature(StandAloneSignature?, bool, object?)
Adds a stand-alone signature to the buffer.
public MetadataToken AddStandAloneSignature(StandAloneSignature? signature, bool allowDuplicates, object? diagnosticSource = null)
Parameters
signatureStandAloneSignatureThe signature to add.
allowDuplicatesbooltrueif the row is always to be added to the end of the buffer,falseif a duplicated row is supposed to be removed and the token of the original should be returned instead.diagnosticSourceobjectThe object that referenced the standalone signature.
Returns
- MetadataToken
The newly assigned metadata token.
AddTypeReference(TypeReference?, bool, bool)
Adds a type reference to the buffer.
public MetadataToken AddTypeReference(TypeReference? type, bool allowDuplicates, bool preserveRid)
Parameters
typeTypeReferenceThe reference to add.
allowDuplicatesbooltrueif the row is always to be added to the end of the buffer,falseif a duplicated row is supposed to be removed and the token of the original should be returned instead.preserveRidbooltrueif the metadata token of the type should be preserved,falseotherwise.
Returns
- MetadataToken
The newly assigned metadata token.
AddTypeSpecification(TypeSpecification?, bool, object?)
Adds a type specification to the buffer.
public MetadataToken AddTypeSpecification(TypeSpecification? type, bool allowDuplicates, object? diagnosticSource = null)
Parameters
typeTypeSpecificationThe specification to add.
allowDuplicatesbooltrueif the row is always to be added to the end of the buffer,falseif a duplicated row is supposed to be removed and the token of the original should be returned instead.diagnosticSourceobjectThe object that referenced the type specification.
Returns
- MetadataToken
The newly assigned metadata token.
CreateDirectory()
Builds the .NET data directory from the buffer.
public DotNetDirectoryBuildResult CreateDirectory()
Returns
DefineAssembly(AssemblyDefinition)
Adds an assembly, its entire manifest module, and all secondary module file references, to the buffer.
public void DefineAssembly(AssemblyDefinition assembly)
Parameters
assemblyAssemblyDefinitionThe assembly to add.
DefineEvents(IEnumerable<EventDefinition>)
Allocates metadata rows for the provided event definitions in the buffer.
public void DefineEvents(IEnumerable<EventDefinition> events)
Parameters
eventsIEnumerable<EventDefinition>The events to define.
DefineFields(IEnumerable<FieldDefinition>)
Allocates metadata rows for the provided field definitions in the buffer.
public void DefineFields(IEnumerable<FieldDefinition> fields)
Parameters
fieldsIEnumerable<FieldDefinition>The fields to define.
DefineManifestResource(ManifestResource, bool)
Adds a single manifest resource to the buffer.
public MetadataToken DefineManifestResource(ManifestResource resource, bool deduplicateData = true)
Parameters
resourceManifestResourceThe resource to add.
deduplicateDatabooltrueif resource data can be reused when identical,falsewhen each embedded resource should get its own data offset.
Returns
- MetadataToken
The new metadata token of the resource.
DefineManifestResources(IEnumerable<ManifestResource>, bool)
Adds a collection of manifest resources to the directory buffer.
public void DefineManifestResources(IEnumerable<ManifestResource> resources, bool deduplicateData = true)
Parameters
resourcesIEnumerable<ManifestResource>The resources to add.
deduplicateDatabooltrueif resource data can be reused when identical,falsewhen each embedded resource should get its own data offset.
DefineMethods(IEnumerable<MethodDefinition>, bool)
Allocates metadata rows for the provided method definitions in the buffer.
public void DefineMethods(IEnumerable<MethodDefinition> methods, bool validateSignatures = true)
Parameters
methodsIEnumerable<MethodDefinition>The methods to define.
validateSignaturesboolSet to
trueif the signatures should be validated for consistency with what is defined in metadata.
DefineModule(ModuleDefinition)
Adds a module metadata row to the buffer.
public void DefineModule(ModuleDefinition module)
Parameters
moduleModuleDefinitionThe module to add.
Remarks
This method only adds the metadata row of the module definition to the module table buffer, it does not add any type definition to the buffer, nor does it add custom attributes or any other metadata model object related to this module to the buffer.
DefineParameters(IEnumerable<ParameterDefinition>)
Allocates metadata rows for the provided parameter definitions in the buffer.
public void DefineParameters(IEnumerable<ParameterDefinition> parameters)
Parameters
parametersIEnumerable<ParameterDefinition>The parameters to define.
DefineProperties(IEnumerable<PropertyDefinition>)
Allocates metadata rows for the provided property definitions in the buffer.
public void DefineProperties(IEnumerable<PropertyDefinition> properties)
Parameters
propertiesIEnumerable<PropertyDefinition>The properties to define.
DefineTypes(IEnumerable<TypeDefinition>)
Allocates metadata rows for the provided type definitions in the buffer.
public void DefineTypes(IEnumerable<TypeDefinition> types)
Parameters
typesIEnumerable<TypeDefinition>The types to define.
Remarks
This method does not define any member defined in the type, except for nested types.
FinalizeModule(ModuleDefinition)
Finalizes the module definition.
public void FinalizeModule(ModuleDefinition module)
Parameters
moduleModuleDefinitionThe module to finalize.
FinalizeTypes()
Finalizes all type definitions added in the buffer.
public void FinalizeTypes()
GetAssemblyReferenceToken(AssemblyReference?, object?)
Gets the newly assigned metadata token of a assembly reference stored in a tables stream or tables stream buffer.
public MetadataToken GetAssemblyReferenceToken(AssemblyReference? assembly, object? diagnosticSource = null)
Parameters
assemblyAssemblyReferenceThe reference to the assembly to add.
diagnosticSourceobjectWhen available, the object that is reported in diagnostics when obtaining the token fails.
Returns
- MetadataToken
The metadata token of the added assembly reference.
GetEventDefinitionToken(EventDefinition?)
Gets the newly assigned metadata token of an event definition stored in a tables stream or tables stream buffer.
public MetadataToken GetEventDefinitionToken(EventDefinition? @event)
Parameters
eventEventDefinitionThe reference to the event to add.
Returns
- MetadataToken
The metadata token of the added event definition.
GetFieldDefinitionToken(FieldDefinition?, object?)
Gets the newly assigned metadata token of a type definition stored in a tables stream or tables stream buffer.
public MetadataToken GetFieldDefinitionToken(FieldDefinition? field, object? diagnosticSource = null)
Parameters
fieldFieldDefinitionThe reference to the field to add.
diagnosticSourceobjectWhen available, the object that is reported in diagnostics when obtaining the token fails.
Returns
- MetadataToken
The metadata token of the added field definition.
GetMemberReferenceToken(MemberReference?, object?)
Gets the newly assigned metadata token of a member reference stored in a tables stream or tables stream buffer.
public MetadataToken GetMemberReferenceToken(MemberReference? member, object? diagnosticSource = null)
Parameters
memberMemberReferenceThe reference to the member to add.
diagnosticSourceobjectWhen available, the object that is reported in diagnostics when obtaining the token fails.
Returns
- MetadataToken
The metadata token of the added member reference.
GetMethodDefinitionToken(MethodDefinition?, object?)
Gets the newly assigned metadata token of a method definition stored in a tables stream or tables stream buffer.
public MetadataToken GetMethodDefinitionToken(MethodDefinition? method, object? diagnosticSource = null)
Parameters
methodMethodDefinitionThe reference to the method to add.
diagnosticSourceobjectWhen available, the object that is reported in diagnostics when obtaining the token fails.
Returns
- MetadataToken
The metadata token of the added method definition.
GetMethodSpecificationToken(MethodSpecification?, object?)
Gets the newly assigned metadata token of a method specification stored in a tables stream or tables stream buffer.
public MetadataToken GetMethodSpecificationToken(MethodSpecification? method, object? diagnosticSource = null)
Parameters
methodMethodSpecificationThe reference to the method to add.
diagnosticSourceobjectWhen available, the object that is reported in diagnostics when obtaining the token fails.
Returns
- MetadataToken
The metadata token of the added method specification.
GetModuleReferenceToken(ModuleReference?, object?)
Adds a single module reference to the buffer.
public MetadataToken GetModuleReferenceToken(ModuleReference? reference, object? diagnosticSource = null)
Parameters
referenceModuleReferenceThe reference to add.
diagnosticSourceobjectThe object that referenced the module.
Returns
- MetadataToken
The new metadata token assigned to the module reference.
GetParameterDefinitionToken(ParameterDefinition?)
Gets the newly assigned metadata token of a parameter definition stored in a tables stream or tables stream buffer.
public MetadataToken GetParameterDefinitionToken(ParameterDefinition? parameter)
Parameters
parameterParameterDefinitionThe reference to the parameter to add.
Returns
- MetadataToken
The metadata token of the added parameter definition.
GetPropertyDefinitionToken(PropertyDefinition?)
Gets the newly assigned metadata token of a property definition stored in a tables stream or tables stream buffer.
public MetadataToken GetPropertyDefinitionToken(PropertyDefinition? property)
Parameters
propertyPropertyDefinitionThe reference to the property to add.
Returns
- MetadataToken
The metadata token of the added property definition.
GetStandAloneSignatureToken(StandAloneSignature?, object?)
Gets the newly assigned metadata token of a stand-alone signature stored in a tables stream or tables stream buffer.
public MetadataToken GetStandAloneSignatureToken(StandAloneSignature? signature, object? diagnosticSource = null)
Parameters
signatureStandAloneSignatureThe reference to the signature to add.
diagnosticSourceobjectWhen available, the object that is reported in diagnostics when obtaining the token fails.
Returns
- MetadataToken
The metadata token of the added signature.
GetTypeDefOrRefIndex(ITypeDefOrRef?, object?)
Obtains a coded index to the provided type reference.
public uint GetTypeDefOrRefIndex(ITypeDefOrRef? type, object? diagnosticSource = null)
Parameters
typeITypeDefOrRefThe type.
diagnosticSourceobjectWhen available, the object that is reported in diagnostics when index encoding of the type fails.
Returns
- uint
The coded index.
GetTypeDefinitionToken(TypeDefinition?, object?)
Gets the newly assigned metadata token of a type definition stored in a tables stream or tables stream buffer.
public MetadataToken GetTypeDefinitionToken(TypeDefinition? type, object? diagnosticSource = null)
Parameters
typeTypeDefinitionThe reference to the type to add.
diagnosticSourceobjectWhen available, the object that is reported in diagnostics when obtaining the token fails.
Returns
- MetadataToken
The metadata token of the added type definition.
GetTypeReferenceToken(TypeReference?, object?)
Gets the newly assigned metadata token of a type reference stored in a tables stream or tables stream buffer.
public MetadataToken GetTypeReferenceToken(TypeReference? type, object? diagnosticSource = null)
Parameters
typeTypeReferenceThe reference to the type to add.
diagnosticSourceobjectWhen available, the object that is reported in diagnostics when obtaining the token fails.
Returns
- MetadataToken
The metadata token of the added type reference.
GetTypeSpecificationToken(TypeSpecification?, object?)
Gets the newly assigned metadata token of a type specification. stored in a tables stream or tables stream buffer.
public MetadataToken GetTypeSpecificationToken(TypeSpecification? type, object? diagnosticSource = null)
Parameters
typeTypeSpecificationThe reference to the type to add.
diagnosticSourceobjectWhen available, the object that is reported in diagnostics when obtaining the token fails.
Returns
- MetadataToken
The metadata token of the added type specification.
GetUserStringIndex(string)
Gets the index to a user-string referenced in a CIL method body.
public uint GetUserStringIndex(string value)
Parameters
valuestringThe string value.
Returns
- uint
The index.