Table of Contents

Class AssemblyDescriptor

Namespace
AsmResolver.DotNet
Assembly
AsmResolver.DotNet.dll

Provides a base implementation for describing a self-describing .NET assembly hosted by a common language runtime (CLR).

public abstract class AssemblyDescriptor : MetadataMember, IHasCustomAttribute, IMetadataMember, IFullNameProvider, INameProvider, IImportable
Inheritance
AssemblyDescriptor
Implements
Derived
Inherited Members
Extension Methods

Constructors

AssemblyDescriptor(MetadataToken)

Initializes a new empty assembly descriptor.

protected AssemblyDescriptor(MetadataToken token)

Parameters

token MetadataToken

The token of the assembly descriptor.

Fields

CustomAttributesInternal

The internal custom attribute list.

protected IList<CustomAttribute>? CustomAttributesInternal

Field Value

IList<CustomAttribute>

Remarks

This value may not be initialized. Use CustomAttributes instead.

Properties

Attributes

Gets or sets the attributes associated to the assembly.

public AssemblyAttributes Attributes { get; set; }

Property Value

AssemblyAttributes

Remarks

This property corresponds to the Attributes column in the assembly table.

Culture

Gets or sets the locale string of the assembly (if available).

public Utf8String? Culture { get; set; }

Property Value

Utf8String

Remarks

If this value is set to null, the default locale will be used

This property corresponds to the Culture column in the assembly table.

CustomAttributes

Gets a collection of custom attributes assigned to this member.

public IList<CustomAttribute> CustomAttributes { get; }

Property Value

IList<CustomAttribute>

DisableJitCompileOptimizer

Gets or sets a value indicating any just-in-time (JIT) compiler optimization is disabled for the assembly.

public bool DisableJitCompileOptimizer { get; set; }

Property Value

bool

Remarks

This attribute originates from the DebuggableAttribute attribute.

EnableJitCompileTracking

Gets or sets a value indicating just-in-time (JIT) compiler tracking is enabled for the assembly.

public bool EnableJitCompileTracking { get; set; }

Property Value

bool

Remarks

This attribute originates from the DebuggableAttribute attribute.

FullName

Gets the full name of the object.

public string FullName { get; }

Property Value

string

HasCustomAttributes

Gets a value indicating whether the member is assigned custom attributes.

public virtual bool HasCustomAttributes { get; }

Property Value

bool

HasPublicKey

Gets or sets a value indicating whether the assembly holds the full (unhashed) public key.

public bool HasPublicKey { get; set; }

Property Value

bool

IsRetargetable

Gets or sets a value indicating whether the assembly can be retargeted (at runtime) to an assembly from a different publisher.

public bool IsRetargetable { get; set; }

Property Value

bool

IsWindowsRuntime

Gets or sets a value indicating whether the assembly contains Windows Runtime (WinRT) code or not.

public bool IsWindowsRuntime { get; set; }

Property Value

bool

Name

Gets or sets the name of the assembly.

public Utf8String? Name { get; set; }

Property Value

Utf8String

Remarks

This property corresponds to the Name column in the assembly table.

Version

Gets or sets the version of the assembly.

public Version Version { get; set; }

Property Value

Version

Remarks

This property corresponds to the MajorVersion, MinorVersion, BuildNumber and RevisionNumber columns in the assembly table.

Methods

ComputePublicKeyToken(byte[], AssemblyHashAlgorithm)

Computes the token of a public key using the provided hashing algorithm.

protected static byte[] ComputePublicKeyToken(byte[] publicKey, AssemblyHashAlgorithm algorithm)

Parameters

publicKey byte[]

The public key to obtain the token from.

algorithm AssemblyHashAlgorithm

The algorithm to use.

Returns

byte[]

The public key token.

GetCulture()

Obtains the locale string of the assembly definition.

protected virtual Utf8String? GetCulture()

Returns

Utf8String

The locale string.

Remarks

This method is called upon initializing the Culture property.

GetCustomAttributes()

Obtains the list of custom attributes assigned to the member.

protected virtual IList<CustomAttribute> GetCustomAttributes()

Returns

IList<CustomAttribute>

The attributes

Remarks

This method is called upon initialization of the CustomAttributes property.

GetName()

Obtains the name of the assembly definition.

protected virtual Utf8String? GetName()

Returns

Utf8String

The name.

Remarks

This method is called upon initializing the Name property.

GetPublicKeyToken()

When the application is signed with a strong name, obtains the public key token of the assembly

public abstract byte[]? GetPublicKeyToken()

Returns

byte[]

The token.

ImportWith(ReferenceImporter)

Imports the assembly descriptor using the provided reference importer.

public abstract AssemblyReference ImportWith(ReferenceImporter importer)

Parameters

importer ReferenceImporter

The importer object to use.

Returns

AssemblyReference

The imported assembly reference.

IsCorLib(in DotNetRuntimeInfo)

Determines whether the assembly descriptor references a Common Object Runtime standard library, according to the provided host runtime.

public bool IsCorLib(in DotNetRuntimeInfo contextRuntime)

Parameters

contextRuntime DotNetRuntimeInfo

The runtime to assume the host is running as.

Returns

bool

true if it is considered a corlib according to the provided runtime, false otherwise.

IsImplementationCorLib(in DotNetRuntimeInfo)

Determines whether the assembly descriptor references a Common Object Runtime standard implementation library, according to the provided host runtime.

public bool IsImplementationCorLib(in DotNetRuntimeInfo contextRuntime)

Parameters

contextRuntime DotNetRuntimeInfo

The runtime to assume the host is running as.

Returns

bool

true if it is considered a implementation corlib according to the provided runtime, false otherwise.

IsImportedInModule(ModuleDefinition)

Determines whether the descriptor of the member is fully imported in the provided module.

public abstract bool IsImportedInModule(ModuleDefinition module)

Parameters

module ModuleDefinition

The module that is supposed to import the member.

Returns

bool

true if the descriptor of the member is fully imported by the module, false otherwise.

Remarks

This method verifies all references in the descriptor of the member only. It does not verify any additional data or contents (such as a method body) associated to the member.

IsReferenceCorLib(in DotNetRuntimeInfo)

Determines whether the assembly descriptor references a Common Object Runtime standard reference (facade) library, according to the provided host runtime.

public bool IsReferenceCorLib(in DotNetRuntimeInfo contextRuntime)

Parameters

contextRuntime DotNetRuntimeInfo

The runtime to assume the host is running as.

Returns

bool

true if it is considered a facade corlib according to the provided runtime, false otherwise.

Resolve(RuntimeContext?)

Resolves the assembly reference to its definition.

public AssemblyDefinition Resolve(RuntimeContext? context)

Parameters

context RuntimeContext

Returns

AssemblyDefinition

The assembly definition.

Resolve(RuntimeContext?, out AssemblyDefinition?)

Attempts to resolve the assembly reference to its definition.

public abstract ResolutionStatus Resolve(RuntimeContext? context, out AssemblyDefinition? assembly)

Parameters

context RuntimeContext

The context to assume when resolving the assembly.

assembly AssemblyDefinition

The resolved assembly, or null if resolution failed.

Returns

ResolutionStatus

A value describing the success or failure status of the assembly resolution.

ToAssemblyReference()

Constructs a new assembly reference based on the descriptor.

public AssemblyReference ToAssemblyReference()

Returns

AssemblyReference

The reference.

ToString()

public override string ToString()

Returns

string

TryResolve(RuntimeContext?, out AssemblyDefinition?)

Attempts to resolve the assembly reference to its definition.

public bool TryResolve(RuntimeContext? context, out AssemblyDefinition? assembly)

Parameters

context RuntimeContext

The context to assume when resolving the assembly.

assembly AssemblyDefinition

The resolved assembly, or null if resolution failed.

Returns

bool

true if the resolution succeeded, false otherwise.