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
Constructors
TypeSignature()
protected TypeSignature()
Properties
ContextModule
Gets the module that defines the member definition or reference.
public virtual ModuleDefinition? ContextModule { get; }
Property Value
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.
DeclaringType
When this member is defined in a type, gets the enclosing type.
public ITypeDescriptor? DeclaringType { get; }
Property Value
ElementType
Gets the element type of the
public abstract ElementType ElementType { get; }
Property Value
FullName
Gets the full name of the object.
public string FullName { get; }
Property Value
IsValueType
Gets a value indicating whether the type signature is encoded as a value type or a reference type.
public abstract bool IsValueType { get; }
Property Value
Name
Gets the name of the object.
public abstract string? Name { get; }
Property Value
Namespace
Gets the namespace the type resides in.
public abstract string? Namespace { get; }
Property Value
Scope
Gets the resolution scope that defines the type.
public abstract IResolutionScope? Scope { get; }
Property Value
Methods
AcceptVisitor<TResult>(ITypeSignatureVisitor<TResult>)
Visit the current type signature using the provided visitor.
public abstract TResult AcceptVisitor<TResult>(ITypeSignatureVisitor<TResult> visitor)
Parameters
visitorITypeSignatureVisitor<TResult>The visitor to accept.
Returns
- TResult
The result the visitor produced after visiting this type signature.
Type Parameters
TResultThe 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
visitorITypeSignatureVisitor<TState, TResult>The visitor to accept.
stateTStateAdditional state.
Returns
- TResult
The result the visitor produced after visiting this type signature.
Type Parameters
TStateThe type of additional state.
TResultThe 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
contextBlobReaderContextThe blob reader context.
readerBinaryStreamReaderThe 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(RuntimeContext?)
Obtains the direct base class of the type signature.
public virtual TypeSignature? GetDirectBaseClass(RuntimeContext? context)
Parameters
contextRuntimeContext
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(RuntimeContext?)
Obtains the interfaces that are directly implemented by the type.
public virtual IEnumerable<TypeSignature> GetDirectlyImplementedInterfaces(RuntimeContext? context)
Parameters
contextRuntimeContext
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(RuntimeContext?)
Obtains the intermediate type of the type signature.
public virtual TypeSignature GetIntermediateType(RuntimeContext? context)
Parameters
contextRuntimeContext
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(RuntimeContext?)
Obtains the reduced type of the type signature.
public virtual TypeSignature GetReducedType(RuntimeContext? context)
Parameters
contextRuntimeContext
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(RuntimeContext?)
Obtains the underlying type of the type signature.
public virtual TypeSignature GetUnderlyingType(RuntimeContext? context)
Parameters
contextRuntimeContext
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(RuntimeContext?), which may resolve enum types to their underlying type representation.
GetVerificationType(RuntimeContext?)
Obtains the verification type of the type signature.
public virtual TypeSignature GetVerificationType(RuntimeContext? context)
Parameters
contextRuntimeContext
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
importerReferenceImporterThe 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
contextGenericContextThe 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, RuntimeContext?)
Determines whether the current type is assignable to the provided type.
public bool IsAssignableTo(TypeSignature other, RuntimeContext? context)
Parameters
otherTypeSignatureThe other type.
contextRuntimeContextThe runtime context to assume when comparing the types.
Returns
- bool
trueif the type is assignable toother,falseotherwise.
Remarks
Type compatibility is determined according to the rules in ECMA-335 I.8.7.3.
IsAssignableTo(TypeSignature, RuntimeContext?, SignatureComparer)
Determines whether the current type is assignable to the provided type.
public bool IsAssignableTo(TypeSignature other, RuntimeContext? context, SignatureComparer comparer)
Parameters
otherTypeSignatureThe other type.
contextRuntimeContextThe runtime context to assume when comparing the types.
comparerSignatureComparerThe comparer to use for comparing type signatures.
Returns
- bool
trueif the type is assignable toother,falseotherwise.
Remarks
Type compatibility is determined according to the rules in ECMA-335 I.8.7.3.
IsCompatibleWith(TypeSignature, RuntimeContext?)
Determines whether the current type is compatible with the provided type.
public bool IsCompatibleWith(TypeSignature other, RuntimeContext? context)
Parameters
otherTypeSignatureThe other type.
contextRuntimeContextThe runtime context to assume when comparing the types.
Returns
- bool
trueif the type is compatible withother,falseotherwise.
Remarks
Type compatibility is determined according to the rules in ECMA-335 I.8.7.1.
IsCompatibleWith(TypeSignature, RuntimeContext?, SignatureComparer)
Determines whether the current type is compatible with the provided type.
public bool IsCompatibleWith(TypeSignature other, RuntimeContext? context, SignatureComparer comparer)
Parameters
otherTypeSignatureThe other type.
contextRuntimeContextThe runtime context to assume when comparing the types.
comparerSignatureComparerThe comparer to use for comparing type signatures.
Returns
- bool
trueif the type is compatible withother,falseotherwise.
Remarks
Type compatibility is determined according to the rules in ECMA-335 I.8.7.1.
IsDirectlyCompatibleWith(TypeSignature, RuntimeContext?, SignatureComparer)
Determines whether the current type is directly compatible with the provided type.
protected virtual bool IsDirectlyCompatibleWith(TypeSignature other, RuntimeContext? context, SignatureComparer comparer)
Parameters
otherTypeSignatureThe other type.
contextRuntimeContextThe runtime context to assume when comparing the types.
comparerSignatureComparerThe comparer to use for comparing type signatures.
Returns
- bool
trueif the types are directly compatible,falseotherwise.
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
moduleModuleDefinitionThe module that is supposed to import the member.
Returns
- bool
trueif the descriptor of the member is fully imported by the module,falseotherwise.
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.
MakeArrayType(params ArrayDimension[])
Constructs a new single-dimension, zero based array signature with the provided type descriptor as element type.
public ArrayTypeSignature MakeArrayType(params ArrayDimension[] dimensions)
Parameters
dimensionsArrayDimension[]The dimensions of the array.
Returns
- ArrayTypeSignature
The constructed array type signature.
MakeArrayType(int)
Constructs a new single-dimension, zero based array signature with the provided type descriptor as element type.
public ArrayTypeSignature MakeArrayType(int dimensionCount)
Parameters
dimensionCountintThe number of dimensions in the array.
Returns
- ArrayTypeSignature
The constructed array type signature.
MakeBoxedType()
Constructs a new boxed type signature with the provided type descriptor as element type. as element type.
public BoxedTypeSignature MakeBoxedType()
Returns
- BoxedTypeSignature
The constructed boxed type signature.
MakeByReferenceType()
Constructs a new by-reference type signature with the provided type descriptor as element type. as element type.
public ByReferenceTypeSignature MakeByReferenceType()
Returns
- ByReferenceTypeSignature
The constructed by-reference type signature.
MakeModifierType(ITypeDefOrRef, bool)
Constructs a new pointer type signature with the provided type descriptor as element type. as element type.
public CustomModifierTypeSignature MakeModifierType(ITypeDefOrRef modifierType, bool isRequired)
Parameters
modifierTypeITypeDefOrRefThe modifier type to add.
isRequiredboolIndicates whether the modifier is required or optional.
Returns
- CustomModifierTypeSignature
The constructed by-reference type signature.
MakePinnedType()
Constructs a new pinned type signature with the provided type descriptor as element type. as element type.
public PinnedTypeSignature MakePinnedType()
Returns
- PinnedTypeSignature
The constructed by-reference type signature.
MakePointerType()
Constructs a new pointer type signature with the provided type descriptor as element type. as element type.
public PointerTypeSignature MakePointerType()
Returns
- PointerTypeSignature
The constructed by-reference type signature.
MakeSzArrayType()
Constructs a new single-dimension, zero based array signature with the provided type descriptor as element type.
public SzArrayTypeSignature MakeSzArrayType()
Returns
- SzArrayTypeSignature
The constructed array type signature.
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
contextBlobReaderContextThe blob reader context.
readerBinaryStreamReaderThe blob reader.
allowTypeSpecboolIndicates 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.
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()
public override string ToString()
Returns
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
contextBlobSerializationContextThe output stream.
typeITypeDefOrRefThe type to write.
propertyNamestringThe property name that was written.