Table of Contents

Class TypeSignature

Namespace
AsmResolver.DotNet.Signatures
Assembly
AsmResolver.DotNet.dll

Provides a base for blob signatures that reference a type.

public abstract class TypeSignature : ExtendableBlobSignature, ITypeDescriptor, IMemberDescriptor, IFullNameProvider, INameProvider, IModuleProvider, IImportable
Inheritance
TypeSignature
Implements
Derived
Inherited Members
Extension Methods

Properties

DeclaringType

When this member is defined in a type, gets the enclosing type.

public ITypeDescriptor? DeclaringType { get; }

Property Value

ITypeDescriptor

ElementType

Gets the element type of the

public abstract ElementType ElementType { get; }

Property Value

ElementType

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 abstract bool IsValueType { get; }

Property Value

bool

Module

Gets the module that defines the member definition or reference.

public virtual ModuleDefinition? Module { get; }

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 the name of the object.

public abstract string? Name { get; }

Property Value

string

Namespace

Gets the namespace the type resides in.

public abstract string? Namespace { get; }

Property Value

string

Scope

Gets the resolution scope that defines the type.

public abstract IResolutionScope? Scope { get; }

Property Value

IResolutionScope

Methods

AcceptVisitor<TResult>(ITypeSignatureVisitor<TResult>)

Visit the current type signature using the provided visitor.

public abstract TResult AcceptVisitor<TResult>(ITypeSignatureVisitor<TResult> visitor)

Parameters

visitor ITypeSignatureVisitor<TResult>

The visitor to accept.

Returns

TResult

The result the visitor produced after visiting this type signature.

Type Parameters

TResult

The type of result the visitor produces.

AcceptVisitor<TState, TResult>(ITypeSignatureVisitor<TState, TResult>, TState)

Visit the current type signature using the provided visitor.

public abstract TResult AcceptVisitor<TState, TResult>(ITypeSignatureVisitor<TState, TResult> visitor, TState state)

Parameters

visitor ITypeSignatureVisitor<TState, TResult>

The visitor to accept.

state TState

Additional state.

Returns

TResult

The result the visitor produced after visiting this type signature.

Type Parameters

TState

The type of additional state.

TResult

The type of result the visitor produces.

FromReader(ref BlobReaderContext, ref BinaryStreamReader)

Reads a type signature from a blob reader.

public static TypeSignature FromReader(ref BlobReaderContext context, ref BinaryStreamReader reader)

Parameters

context BlobReaderContext

The blob reader context.

reader BinaryStreamReader

The blob signature reader.

Returns

TypeSignature

The type signature.

Exceptions

ArgumentOutOfRangeException

Occurs when the blob reader points to an element type that is invalid or unsupported.

GetDirectBaseClass()

Obtains the direct base class of the type signature.

public virtual TypeSignature? GetDirectBaseClass()

Returns

TypeSignature

The type representing the immediate base class.

Remarks

The direct base class is computed according to the rules defined in ECMA-335 I.8.7, where interfaces will extend object, and generic base types will be instantiated with the derived classes type arguments (if any).

GetDirectlyImplementedInterfaces()

Obtains the interfaces that are directly implemented by the type.

public virtual IEnumerable<TypeSignature> GetDirectlyImplementedInterfaces()

Returns

IEnumerable<TypeSignature>

The interfaces.

Remarks

The result set of types is computed according to the rules defined in ECMA-335 I.8.7, where interfaces will extend object, and generic interfaces will be instantiated with the derived classes type arguments (if any).

GetIntermediateType()

Obtains the intermediate type of the type signature.

public virtual TypeSignature GetIntermediateType()

Returns

TypeSignature

The intermediate type.

Remarks

As per ECMA-335 I.8.7, intermediate types are a subset of the built-in value types can be represented on the evaluation stack.

GetReducedType()

Obtains the reduced type of the type signature.

public virtual TypeSignature GetReducedType()

Returns

TypeSignature

The reduced type.

Remarks

As per ECMA-335 I.8.7, the reduced type ignores the semantic differences between enumerations and the signed and unsigned integer types; treating these types the same if they have the same number of bits.

GetUnderlyingType()

Obtains the underlying type of the type signature.

public virtual TypeSignature GetUnderlyingType()

Returns

TypeSignature

The underlying type.

Remarks

This method computes the underlying type as per ECMA-335 I.8.7, and may therefore attempt to resolve assemblies to determine whether the type is an enum or not. It should not be confused with GetUnderlyingTypeDefOrRef(), which merely obtains the ITypeDefOrRef instance behind the type signature.

GetUnderlyingTypeDefOrRef()

Gets the underlying base type signature, without any extra adornments.

public abstract ITypeDefOrRef? GetUnderlyingTypeDefOrRef()

Returns

ITypeDefOrRef

The base signature.

Remarks

This is not to be confused with GetUnderlyingType(), which may resolve enum types to their underlying type representation.

GetVerificationType()

Obtains the verification type of the type signature.

public virtual TypeSignature GetVerificationType()

Returns

TypeSignature

The verification type.

Remarks

As per ECMA-335 I.8.7, the verification type ignores the semantic differences between enumerations, characters, booleans, the signed and unsigned integer types, and managed pointers to any of these; treating these types the same if they have the same number of bits or point to types with the same number of bits.

ImportWith(ReferenceImporter)

Imports the type signature using the provided reference importer object.

public TypeSignature ImportWith(ReferenceImporter importer)

Parameters

importer ReferenceImporter

The reference importer to us.

Returns

TypeSignature

The imported type.

InstantiateGenericTypes(GenericContext)

Substitutes any generic type parameter in the type signature with the parameters provided by the generic context.

public TypeSignature InstantiateGenericTypes(GenericContext context)

Parameters

context GenericContext

The generic context.

Returns

TypeSignature

The instantiated type signature.

Remarks

When the type signature does not contain any generic parameter, this method might return the current instance of the type signature.

IsAssignableTo(TypeSignature)

Determines whether the current type is assignable to the provided type.

public bool IsAssignableTo(TypeSignature other)

Parameters

other TypeSignature

The other type.

Returns

bool

true if the type is assignable to other, false otherwise.

Remarks

Type compatibility is determined according to the rules in ECMA-335 I.8.7.3.

IsAssignableTo(TypeSignature, SignatureComparer)

Determines whether the current type is assignable to the provided type.

public bool IsAssignableTo(TypeSignature other, SignatureComparer comparer)

Parameters

other TypeSignature

The other type.

comparer SignatureComparer

The comparer to use for comparing type signatures.

Returns

bool

true if the type is assignable to other, false otherwise.

Remarks

Type compatibility is determined according to the rules in ECMA-335 I.8.7.3.

IsCompatibleWith(TypeSignature)

Determines whether the current type is compatible with the provided type.

public bool IsCompatibleWith(TypeSignature other)

Parameters

other TypeSignature

The other type.

Returns

bool

true if the type is compatible with other, false otherwise.

Remarks

Type compatibility is determined according to the rules in ECMA-335 I.8.7.1.

IsCompatibleWith(TypeSignature, SignatureComparer)

Determines whether the current type is compatible with the provided type.

public bool IsCompatibleWith(TypeSignature other, SignatureComparer comparer)

Parameters

other TypeSignature

The other type.

comparer SignatureComparer

The comparer to use for comparing type signatures.

Returns

bool

true if the type is compatible with other, false otherwise.

Remarks

Type compatibility is determined according to the rules in ECMA-335 I.8.7.1.

IsDirectlyCompatibleWith(TypeSignature, SignatureComparer)

Determines whether the current type is directly compatible with the provided type.

protected virtual bool IsDirectlyCompatibleWith(TypeSignature other, SignatureComparer comparer)

Parameters

other TypeSignature

The other type.

comparer SignatureComparer

The comparer to use for comparing type signatures.

Returns

bool

true if the types are directly compatible, false otherwise.

Remarks

Type compatibility is determined according to the rules in ECMA-335 I.8.7.1., excluding the transitivity rule.

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.

ReadTypeDefOrRef(ref BlobReaderContext, ref BinaryStreamReader, bool)

Reads a TypeDefOrRef coded index from the provided blob reader.

protected static ITypeDefOrRef ReadTypeDefOrRef(ref BlobReaderContext context, ref BinaryStreamReader reader, bool allowTypeSpec)

Parameters

context BlobReaderContext

The blob reader context.

reader BinaryStreamReader

The blob reader.

allowTypeSpec bool

Indicates the coded index to the type is allowed to be decoded to a member in the type specification table.

Returns

ITypeDefOrRef

The decoded and resolved type definition or reference.

Resolve()

Resolves the reference to a type definition.

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

StripModifiers()

Strips any top-level custom type modifier and pinned type annotations from the signature.

public virtual TypeSignature StripModifiers()

Returns

TypeSignature

The stripped type signature.

Remarks

This method does not necessarily recursively strip away every modifier type from the signature, nor does it allocate new type signatures or change existing ones. It only traverses the type signature until a non-modifier or pinned type is encountered. Annotations that are embedded in the type signature (e.g., as a type argument of a generic instance type), will not be automatically removed.

ToString()

Returns a string that represents the current object.

public override string ToString()

Returns

string

A string that represents the current object.

ToTypeDefOrRef()

Transforms the type descriptor to an instance of a ITypeDefOrRef, which can be referenced by a metadata token.

public virtual ITypeDefOrRef ToTypeDefOrRef()

Returns

ITypeDefOrRef

The constructed TypeDefOrRef instance.

WriteTypeDefOrRef(BlobSerializationContext, ITypeDefOrRef?, string)

Writes a TypeDefOrRef coded index to the output stream.

protected void WriteTypeDefOrRef(BlobSerializationContext context, ITypeDefOrRef? type, string propertyName)

Parameters

context BlobSerializationContext

The output stream.

type ITypeDefOrRef

The type to write.

propertyName string

The property name that was written.