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
parentIMemberRefParentfieldNameUtf8StringThe name of the field to reference.
signatureFieldSignatureThe 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
parentIMemberRefParentfieldNameUtf8StringThe name of the field to reference.
fieldTypeTypeSignatureThe 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
parentIMemberRefParentmemberNameUtf8StringThe name of the member to reference.
signatureMemberSignatureThe 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
parentIMemberRefParentmethodNameUtf8StringThe name of the method to reference.
signatureMethodSignatureThe 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
scopeIResolutionScopensUtf8StringThe namespace of the type.
nameUtf8StringThe 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
scopeIResolutionScopensstringThe namespace of the type.
namestringThe 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
typeITypeDefOrRefnestedTypeNameUtf8StringThe 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
typeITypeDefOrRefnestedTypeNamestringThe 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
typeITypeDescriptorcontextRuntimeContextThe runtime context that is assumed.
Returns
- bool
truewhen the type is considered a value type,falsewhen 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
typeITypeDescriptornsstringThe namespace.
namestringThe name.
Returns
- bool
trueif the name and the namespace of the type matches the provided values,falseotherwise.
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
typeITypeDefOrRefnsUtf8StringThe namespace.
nameUtf8StringThe name.
Returns
- bool
trueif the name and the namespace of the type matches the provided values,falseotherwise.
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
typeITypeDefOrRefisValueTypebooltrueif the type is a value type,falseotherwise.typeArgumentsTypeSignature[]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
typeITypeDescriptorcontextRuntimeContextThe runtime context to assume when constructing the signature, if any.
typeArgumentsTypeSignature[]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
typeITypeDescriptorisValueTypebooltrueif the type is a value type,falseotherwise.typeArgumentsTypeSignature[]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
fieldIFieldDescriptorcontextRuntimeContextThe 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
methodIMethodDescriptorcontextRuntimeContextThe 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
typeITypeDescriptorcontextRuntimeContextThe 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
typeITypeDefOrRefcontextRuntimeContextThe 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
fieldIFieldDescriptorcontextRuntimeContextThe context to assume when resolving the field.
definitionFieldDefinitionThe resolved field definition, or
nullif resolution failed.
Returns
- bool
trueif the resolution was successful,falseotherwise.
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
methodIMethodDescriptorcontextRuntimeContextThe context to assume when resolving the method.
definitionMethodDefinitionThe resolved method definition, or
nullif resolution failed.
Returns
- bool
trueif the resolution was successful,falseotherwise.
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
typeITypeDescriptorcontextRuntimeContextThe context to assume when resolving the type.
definitionTypeDefinitionThe resolved type definition, or
nullif resolution failed.
Returns
- bool
trueif the resolution was successful,falseotherwise.