Table of Contents

Class TypeReference

Namespace
AsmResolver.DotNet
Assembly
AsmResolver.DotNet.dll

Represents a reference to a type defined in a .NET assembly.

public class TypeReference : MetadataMember, ITypeDefOrRef, ITypeDescriptor, IMemberDescriptor, IFullNameProvider, IMemberRefParent, IHasCustomAttribute, IResolutionScope, IMetadataMember, INameProvider, IModuleProvider, IImportable
Inheritance
TypeReference
Implements
Derived
Inherited Members
Extension Methods

Constructors

TypeReference(IResolutionScope?, Utf8String?, Utf8String?)

Creates a new reference to a type.

public TypeReference(IResolutionScope? scope, Utf8String? ns, Utf8String? name)

Parameters

scope IResolutionScope

The scope that defines the type.

ns Utf8String

The namespace the type resides in.

name Utf8String

The name of the type.

Remarks

The resulting type will inherit the context module from scope.

TypeReference(ModuleDefinition?, IResolutionScope?, Utf8String?, Utf8String?)

Creates a new reference to a type.

public TypeReference(ModuleDefinition? contextModule, IResolutionScope? scope, Utf8String? ns, Utf8String? name)

Parameters

contextModule ModuleDefinition

The module that references the type.

scope IResolutionScope

The scope that defines the type.

ns Utf8String

The namespace the type resides in.

name Utf8String

The name of the type.

TypeReference(MetadataToken)

Initializes a new empty type reference.

protected TypeReference(MetadataToken token)

Parameters

token MetadataToken

The token of the type reference.

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

ContextModule

Gets the module that defines the member definition or reference.

public ModuleDefinition? ContextModule { get; protected set; }

Property Value

ModuleDefinition

Remarks

For member references, this does not obtain the module definition that the member is defined in. Rather, it obtains the module definition that references this reference.

CustomAttributes

Gets a collection of custom attributes assigned to this member.

public IList<CustomAttribute> CustomAttributes { get; }

Property Value

IList<CustomAttribute>

DeclaringType

When this type is nested, gets the enclosing type.

public ITypeDefOrRef? DeclaringType { get; }

Property Value

ITypeDefOrRef

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

Name

Gets or sets the name of the referenced type.

public Utf8String? Name { get; set; }

Property Value

Utf8String

Remarks

This property corresponds to the Name column in the type reference table.

Namespace

Gets or sets the namespace the type is residing in.

public Utf8String? Namespace { get; set; }

Property Value

Utf8String

Remarks

This property corresponds to the Namespace column in the type definition table.

Scope

Gets the resolution scope that defines the type.

public IResolutionScope? Scope { get; set; }

Property Value

IResolutionScope

Methods

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 type reference.

protected virtual Utf8String? GetName()

Returns

Utf8String

The name.

Remarks

This method is called upon initialization of the Name property.

GetNamespace()

Obtains the namespace of the type reference.

protected virtual Utf8String? GetNamespace()

Returns

Utf8String

The namespace.

Remarks

This method is called upon initialization of the Namespace property.

GetScope()

Obtains the scope of the type reference.

protected virtual IResolutionScope? GetScope()

Returns

IResolutionScope

The scope.

Remarks

This method is called upon initialization of the Scope property.

ImportWith(ReferenceImporter)

Imports the type reference using the provided reference importer object.

public ITypeDefOrRef ImportWith(ReferenceImporter importer)

Parameters

importer ReferenceImporter

The reference importer to use.

Returns

ITypeDefOrRef

The imported type.

IsImportedInModule(ModuleDefinition)

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

public 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.

Resolve(RuntimeContext?, out TypeDefinition?)

Attempts to resolve the type reference to its definition, assuming the provided module as resolution context.

public ResolutionStatus Resolve(RuntimeContext? context, out TypeDefinition? definition)

Parameters

context RuntimeContext

The context to assume when resolving the type.

definition TypeDefinition

The resolved type definition, or null if the type could not be resolved.

Returns

ResolutionStatus

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

ToString()

public override string ToString()

Returns

string

ToTypeSignature(RuntimeContext?)

Converts the type in a type signature.

public TypeSignature ToTypeSignature(RuntimeContext? context)

Parameters

context RuntimeContext

The runtime context to assume when creating the signature.

Returns

TypeSignature

The new type signature.

Remarks

When this type is a signature, gets the underlying type signature instance. Otherwise, a new signature will be instantiated.

ToTypeSignature(bool)

Transforms the type descriptor to an instance of a TypeSignature, which can be used in blob signatures.

public TypeSignature ToTypeSignature(bool isValueType)

Parameters

isValueType bool

true if the type is a value type, false otherwise.

Returns

TypeSignature

The constructed type signature instance.

Remarks

This function can be used to avoid type resolution on type references.

TryGetIsValueType(RuntimeContext?)

Determines whether the type is considered a value type or reference type by the runtime.

public bool? TryGetIsValueType(RuntimeContext? context)

Parameters

context RuntimeContext

The runtime context that is assumed.

Returns

bool?

true when the type is considered a value type, false when it is a reference type, null when unknown.