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.

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

Creates a new reference to a type.

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

Parameters

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

Properties

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

IsValueType

Gets a value indicating whether instances of this type are passed on by value or by reference.

public bool IsValueType { get; }

Property Value

bool

Module

Gets the module that defines the member definition or reference.

public ModuleDefinition? Module { 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.

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()

Resolves the reference to a type definition.

public TypeDefinition? Resolve()

Returns

TypeDefinition

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

Remarks

This method can only be invoked if the reference was added to a module.

ToString()

Returns a string that represents the current object.

public override string ToString()

Returns

string

A string that represents the current object.

ToTypeSignature()

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

public TypeSignature ToTypeSignature()

Returns

TypeSignature

The constructed type signature instance.

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.