Table of Contents

Class TypeDescriptorExtensions

Namespace
AsmResolver.DotNet
Assembly
AsmResolver.DotNet.dll

Provides convenience extension methods to instances of ITypeDescriptor.

public static class TypeDescriptorExtensions
Inheritance
TypeDescriptorExtensions
Inherited Members

Methods

CreateFieldReference(IMemberRefParent, Utf8String?, FieldSignature?)

Constructs a reference to a field declared within the provided parent member.

public static IFieldDescriptor CreateFieldReference(this IMemberRefParent parent, Utf8String? fieldName, FieldSignature? signature)

Parameters

parent IMemberRefParent
fieldName Utf8String

The name of the field to reference.

signature FieldSignature

The signature of the field to reference.

Returns

IFieldDescriptor

The constructed reference.

CreateFieldReference(IMemberRefParent, Utf8String?, TypeSignature)

Constructs a reference to a field declared within the provided parent member.

public static IFieldDescriptor CreateFieldReference(this IMemberRefParent parent, Utf8String? fieldName, TypeSignature fieldType)

Parameters

parent IMemberRefParent
fieldName Utf8String

The name of the field to reference.

fieldType TypeSignature

The type of the field to reference.

Returns

IFieldDescriptor

The constructed reference.

CreateMemberReference(IMemberRefParent, Utf8String?, MemberSignature?)

Constructs a reference to a member declared within the provided parent member.

public static MemberReference CreateMemberReference(this IMemberRefParent parent, Utf8String? memberName, MemberSignature? signature)

Parameters

parent IMemberRefParent
memberName Utf8String

The name of the member to reference.

signature MemberSignature

The signature of the member to reference.

Returns

MemberReference

The constructed reference.

CreateMethodReference(IMemberRefParent, Utf8String?, MethodSignature?)

Constructs a reference to a method declared within the provided parent member.

public static IMethodDescriptor CreateMethodReference(this IMemberRefParent parent, Utf8String? methodName, MethodSignature? signature)

Parameters

parent IMemberRefParent
methodName Utf8String

The name of the method to reference.

signature MethodSignature

The signature of the method to reference.

Returns

IMethodDescriptor

The constructed reference.

CreateTypeReference(IResolutionScope, Utf8String?, Utf8String)

Constructs a reference to a type within the provided resolution scope.

public static TypeReference CreateTypeReference(this IResolutionScope scope, Utf8String? ns, Utf8String name)

Parameters

scope IResolutionScope
ns Utf8String

The namespace of the type.

name Utf8String

The name of the type.

Returns

TypeReference

The constructed reference.

CreateTypeReference(IResolutionScope, string?, string)

Constructs a reference to a type within the provided resolution scope.

public static TypeReference CreateTypeReference(this IResolutionScope scope, string? ns, string name)

Parameters

scope IResolutionScope
ns string

The namespace of the type.

name string

The name of the type.

Returns

TypeReference

The constructed reference.

CreateTypeReference(ITypeDefOrRef, Utf8String)

Constructs a reference to a nested type.

public static TypeReference CreateTypeReference(this ITypeDefOrRef type, Utf8String nestedTypeName)

Parameters

type ITypeDefOrRef
nestedTypeName Utf8String

The name of the nested type.

Returns

TypeReference

The constructed reference.

Exceptions

ArgumentOutOfRangeException

Occurs when the type cannot be used as a declaring type of the reference.

CreateTypeReference(ITypeDefOrRef, string)

Constructs a reference to a nested type.

public static TypeReference CreateTypeReference(this ITypeDefOrRef type, string nestedTypeName)

Parameters

type ITypeDefOrRef
nestedTypeName string

The name of the nested type.

Returns

TypeReference

The constructed reference.

Exceptions

ArgumentOutOfRangeException

Occurs when the type cannot be used as a declaring type of the reference.

GetIsValueType(ITypeDescriptor, RuntimeContext?)

Determines whether a type is a value type or not.

public static bool GetIsValueType(this ITypeDescriptor type, RuntimeContext? context)

Parameters

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

Exceptions

ArgumentException

Occurs when it could not be determined whether the type descriptor is a value or reference type.

IsTypeOf(ITypeDescriptor, string?, string?)

Determines whether a type matches a namespace and name pair.

public static bool IsTypeOf(this ITypeDescriptor type, string? ns, string? name)

Parameters

type ITypeDescriptor
ns string

The namespace.

name string

The name.

Returns

bool

true if the name and the namespace of the type matches the provided values, false otherwise.

IsTypeOfUtf8(ITypeDefOrRef, Utf8String?, Utf8String?)

Determines whether a type matches a namespace and name pair.

public static bool IsTypeOfUtf8(this ITypeDefOrRef type, Utf8String? ns, Utf8String? name)

Parameters

type ITypeDefOrRef
ns Utf8String

The namespace.

name Utf8String

The name.

Returns

bool

true if the name and the namespace of the type matches the provided values, false otherwise.

MakeGenericInstanceType(ITypeDefOrRef, bool, params TypeSignature[])

Constructs a new generic instance type signature with the provided type descriptor as element type. as element type.

public static GenericInstanceTypeSignature MakeGenericInstanceType(this ITypeDefOrRef type, bool isValueType, params TypeSignature[] typeArguments)

Parameters

type ITypeDefOrRef
isValueType bool

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

typeArguments TypeSignature[]

The arguments to instantiate the type with.

Returns

GenericInstanceTypeSignature

The constructed by-reference type signature.

Remarks

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

MakeGenericInstanceType(ITypeDescriptor, RuntimeContext?, params TypeSignature[])

Constructs a new generic instance type signature with the provided type descriptor as element type. as element type.

public static GenericInstanceTypeSignature MakeGenericInstanceType(this ITypeDescriptor type, RuntimeContext? context, params TypeSignature[] typeArguments)

Parameters

type ITypeDescriptor
context RuntimeContext

The runtime context to assume when constructing the signature, if any.

typeArguments TypeSignature[]

The arguments to instantiate the type with.

Returns

GenericInstanceTypeSignature

The constructed by-reference type signature.

MakeGenericInstanceType(ITypeDescriptor, bool, params TypeSignature[])

Constructs a new generic instance type signature with the provided type descriptor as element type. as element type.

public static GenericInstanceTypeSignature MakeGenericInstanceType(this ITypeDescriptor type, bool isValueType, params TypeSignature[] typeArguments)

Parameters

type ITypeDescriptor
isValueType bool

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

typeArguments TypeSignature[]

The arguments to instantiate the type with.

Returns

GenericInstanceTypeSignature

The constructed by-reference type signature.

Resolve(IFieldDescriptor, RuntimeContext?)

Resolves the field descriptor to its definition given the provided runtime context.

public static FieldDefinition Resolve(this IFieldDescriptor field, RuntimeContext? context)

Parameters

field IFieldDescriptor
context RuntimeContext

The context to assume when resolving the field.

Returns

FieldDefinition

The resolved field definition.

Exceptions

InvalidOperationException

Occurs when the declaring type or the field within the declaring type could not be found.

FileNotFoundException

Occurs when the declaring assembly could not be found.

BadImageFormatException

Occurs when the declaring assembly is invalid.

Resolve(IMethodDescriptor, RuntimeContext?)

Resolves the method descriptor to its definition given the provided runtime context.

public static MethodDefinition Resolve(this IMethodDescriptor method, RuntimeContext? context)

Parameters

method IMethodDescriptor
context RuntimeContext

The context to assume when resolving the method.

Returns

MethodDefinition

The resolved method definition.

Exceptions

InvalidOperationException

Occurs when the declaring type or the method within the declaring type could not be found.

FileNotFoundException

Occurs when the declaring assembly could not be found.

BadImageFormatException

Occurs when the declaring assembly is invalid.

Resolve(ITypeDescriptor, RuntimeContext?)

Resolves the type descriptor to its definition given the provided runtime context.

public static TypeDefinition Resolve(this ITypeDescriptor type, RuntimeContext? context)

Parameters

type ITypeDescriptor
context RuntimeContext

The context to assume when resolving the type.

Returns

TypeDefinition

The resolved type definition.

Exceptions

InvalidOperationException

Occurs when the type could not be found.

FileNotFoundException

Occurs when the declaring assembly could not be found.

BadImageFormatException

Occurs when the declaring assembly is invalid.

ToTypeSignature(ITypeDefOrRef, RuntimeContext?)

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

public static TypeSignature ToTypeSignature(this ITypeDefOrRef type, RuntimeContext? context)

Parameters

type ITypeDefOrRef
context RuntimeContext

The runtime context to assume when constructing the signature, if any.

Returns

TypeSignature

The constructed type signature instance.

Remarks

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

TryResolve(IFieldDescriptor, RuntimeContext?, out FieldDefinition?)

Attempts to resolve the field descriptor in the provided context.

public static bool TryResolve(this IFieldDescriptor field, RuntimeContext? context, out FieldDefinition? definition)

Parameters

field IFieldDescriptor
context RuntimeContext

The context to assume when resolving the field.

definition FieldDefinition

The resolved field definition, or null if resolution failed.

Returns

bool

true if the resolution was successful, false otherwise.

TryResolve(IMethodDescriptor, RuntimeContext?, out MethodDefinition?)

Attempts to resolve the method descriptor in the provided context.

public static bool TryResolve(this IMethodDescriptor method, RuntimeContext? context, out MethodDefinition? definition)

Parameters

method IMethodDescriptor
context RuntimeContext

The context to assume when resolving the method.

definition MethodDefinition

The resolved method definition, or null if resolution failed.

Returns

bool

true if the resolution was successful, false otherwise.

TryResolve(ITypeDescriptor, RuntimeContext?, out TypeDefinition?)

Attempts to resolve the type descriptor in the provided context.

public static bool TryResolve(this ITypeDescriptor type, RuntimeContext? context, out TypeDefinition? definition)

Parameters

type ITypeDescriptor
context RuntimeContext

The context to assume when resolving the type.

definition TypeDefinition

The resolved type definition, or null if resolution failed.

Returns

bool

true if the resolution was successful, false otherwise.