Class TypeDefinition
- Namespace
- AsmResolver.DotNet
- Assembly
- AsmResolver.DotNet.dll
Represents a type (a class, interface or structure) defined in a .NET module.
public class TypeDefinition : MetadataMember, ITypeDefOrRef, ITypeDescriptor, IMemberRefParent, IHasCustomAttribute, IMemberDefinition, IHasGenericParameters, IMemberDescriptor, IFullNameProvider, INameProvider, IModuleProvider, IImportable, IHasSecurityDeclaration, IMetadataMember, IOwnedCollectionElement<ModuleDefinition>, IOwnedCollectionElement<TypeDefinition>
- Inheritance
-
TypeDefinition
- Implements
- Derived
- Inherited Members
- Extension Methods
Constructors
TypeDefinition(MetadataToken)
Initializes a new type definition.
protected TypeDefinition(MetadataToken token)
Parameters
token
MetadataTokenThe token of the type definition.
TypeDefinition(Utf8String?, Utf8String?, TypeAttributes)
Creates a new type definition.
public TypeDefinition(Utf8String? ns, Utf8String? name, TypeAttributes attributes)
Parameters
ns
Utf8StringThe namespace the type resides in.
name
Utf8StringThe name of the type.
attributes
TypeAttributesThe attributes associated to the type.
TypeDefinition(Utf8String?, Utf8String?, TypeAttributes, ITypeDefOrRef?)
Creates a new type definition.
public TypeDefinition(Utf8String? ns, Utf8String? name, TypeAttributes attributes, ITypeDefOrRef? baseType)
Parameters
ns
Utf8StringThe namespace the type resides in.
name
Utf8StringThe name of the type.
attributes
TypeAttributesThe attributes associated to the type.
baseType
ITypeDefOrRefThe super class that this type extends.
Properties
Attributes
Gets or sets the attributes associated to the type.
public TypeAttributes Attributes { get; set; }
Property Value
BaseType
Gets or sets the super class that this type extends.
public ITypeDefOrRef? BaseType { get; set; }
Property Value
ClassLayout
Gets or sets an override to the layout of a class, indicating its total and packing size.
public ClassLayout? ClassLayout { get; set; }
Property Value
Remarks
When this property is set to null
, the runtime decides the layout of the class.
CustomAttributes
Gets a collection of custom attributes assigned to this member.
public IList<CustomAttribute> CustomAttributes { get; }
Property Value
DeclaringType
When this type is nested, gets the enclosing type.
public TypeDefinition? DeclaringType { get; }
Property Value
Events
Gets a collection of events defined in the type.
public IList<EventDefinition> Events { get; }
Property Value
Fields
Gets a collection of fields defined in the type.
public IList<FieldDefinition> Fields { get; }
Property Value
FullName
Gets the full name (including namespace or declaring type full name) of the type.
public string FullName { get; }
Property Value
GenericParameters
Gets a collection of generic parameters this member defines.
public IList<GenericParameter> GenericParameters { get; }
Property Value
HasSecurity
Gets or sets a value indicating the type has additional security attributes associated to it.
public bool HasSecurity { get; set; }
Property Value
Interfaces
Gets a collection of interfaces that are implemented by the type.
public IList<InterfaceImplementation> Interfaces { get; }
Property Value
IsAbstract
Gets or sets a value indicating whether the type is defined abstract and should be extended before an object can be instantiated.
public bool IsAbstract { get; set; }
Property Value
IsAnsiClass
Gets or sets a value indicating whether LPTSTR string instances are interpreted as ANSI strings.
public bool IsAnsiClass { get; set; }
Property Value
IsAutoClass
Gets or sets a value indicating whether LPTSTR string instances are interpreted automatically by the runtime.
public bool IsAutoClass { get; set; }
Property Value
IsAutoLayout
Gets or sets a value indicating whether the fields of the type are auto-laid out by the common language runtime (CLR).
public bool IsAutoLayout { get; set; }
Property Value
IsBeforeFieldInit
Gets or sets a value indicating the runtime should initialize the class before any time before the first static field access.
public bool IsBeforeFieldInit { get; set; }
Property Value
IsByRefLike
Determines whether the type is marked with the IsByRefLike attribute, indicating a ref struct definition.
public bool IsByRefLike { get; }
Property Value
IsClass
Gets or sets a value indicating whether the type is a class.
public bool IsClass { get; set; }
Property Value
IsCustomFormatClass
Gets or sets a value indicating whether LPTSTR string instances are interpreted using a non-standard encoding.
public bool IsCustomFormatClass { get; set; }
Property Value
IsDelegate
Gets a value indicating whether the type describes a delegate referring to a method.
public bool IsDelegate { get; }
Property Value
IsEnum
Gets a value indicating whether the type defines an enumeration of discrete values.
public bool IsEnum { get; }
Property Value
IsExplicitLayout
Gets or sets a value indicating whether the fields of the type are laid out explicitly.
public bool IsExplicitLayout { get; set; }
Property Value
IsForwarder
Gets or sets a value indicating the type is an exported type and forwards the definition to another module.
public bool IsForwarder { get; set; }
Property Value
IsImport
Gets or sets a value indicating whether the type is imported.
public bool IsImport { get; set; }
Property Value
IsInterface
Gets or sets a value indicating whether the type is an interface.
public bool IsInterface { get; set; }
Property Value
IsModuleType
true
if this is the global (i.e., <Module>) type, otherwise false
.
public bool IsModuleType { get; }
Property Value
Remarks
If the global (i.e., <Module>) type was not added or does not exist yet in the Module,
this will return false
.
IsNested
Gets a value indicating whether the type is enclosed by another type.
public bool IsNested { get; }
Property Value
IsNestedAssembly
Gets or sets a value indicating whether the type is nested with assembly visibility.
public bool IsNestedAssembly { get; set; }
Property Value
Remarks
Updating the value of this property does not automatically make the type nested in another type. Similarly, adding this type to another enclosing type will not automatically update this property.
IsNestedFamily
Gets or sets a value indicating whether the type is nested with family visibility.
public bool IsNestedFamily { get; set; }
Property Value
Remarks
Updating the value of this property does not automatically make the type nested in another type. Similarly, adding this type to another enclosing type will not automatically update this property.
IsNestedFamilyAndAssembly
Gets or sets a value indicating whether the type is nested with family and assembly visibility.
public bool IsNestedFamilyAndAssembly { get; set; }
Property Value
Remarks
Updating the value of this property does not automatically make the type nested in another type. Similarly, adding this type to another enclosing type will not automatically update this property.
IsNestedFamilyOrAssembly
Gets or sets a value indicating whether the type is nested with family or assembly visibility.
public bool IsNestedFamilyOrAssembly { get; set; }
Property Value
Remarks
Updating the value of this property does not automatically make the type nested in another type. Similarly, adding this type to another enclosing type will not automatically update this property.
IsNestedPrivate
Gets or sets a value indicating whether the type is nested with private visibility.
public bool IsNestedPrivate { get; set; }
Property Value
Remarks
Updating the value of this property does not automatically make the type nested in another type. Similarly, adding this type to another enclosing type will not automatically update this property.
IsNestedPublic
Gets or sets a value indicating whether the type is nested with public visibility.
public bool IsNestedPublic { get; set; }
Property Value
Remarks
Updating the value of this property does not automatically make the type nested in another type. Similarly, adding this type to another enclosing type will not automatically update this property.
IsNotPublic
Gets a value indicating whether the type is in a public scope or not.
public bool IsNotPublic { get; set; }
Property Value
IsPublic
Gets or sets a value indicating whether the type is in a public scope or not.
public bool IsPublic { get; set; }
Property Value
IsReadOnly
Determines whether the type is marked as read-only.
public bool IsReadOnly { get; }
Property Value
IsRuntimeSpecialName
Gets or sets a value indicating whether the runtime should check the encoding of the name.
public bool IsRuntimeSpecialName { get; set; }
Property Value
IsSealed
Gets or sets a value indicating whether the type is defined sealed and cannot be extended by a sub class.
public bool IsSealed { get; set; }
Property Value
IsSequentialLayout
Gets or sets a value indicating whether the fields of the type are laid out sequentially.
public bool IsSequentialLayout { get; set; }
Property Value
IsSerializable
Gets or sets a value indicating whether the type is serializable.
public bool IsSerializable { get; set; }
Property Value
IsSpecialName
Gets or sets a value indicating whether the type has a special name.
public bool IsSpecialName { get; set; }
Property Value
IsUnicodeClass
Gets or sets a value indicating whether LPTSTR string instances are interpreted as Unicode strings.
public bool IsUnicodeClass { get; set; }
Property Value
IsValueType
Gets a value indicating whether instances of this type are passed on by value or by reference.
public bool IsValueType { get; }
Property Value
MethodImplementations
Gets a collection of methods that are explicitly implemented by the type.
public IList<MethodImplementation> MethodImplementations { get; }
Property Value
Methods
Gets a collection of methods defined in the type.
public IList<MethodDefinition> Methods { get; }
Property Value
Module
Gets the module that defines the type.
public ModuleDefinition? Module { get; }
Property Value
Name
Gets or sets the name of the type.
public Utf8String? Name { get; set; }
Property Value
Remarks
This property corresponds to the Name column in the type definition table.
Namespace
Gets or sets the namespace the type resides in.
public Utf8String? Namespace { get; set; }
Property Value
Remarks
This property corresponds to the Namespace column in the type definition table.
NestedTypes
Gets a collection of nested types that this type defines.
public IList<TypeDefinition> NestedTypes { get; }
Property Value
Properties
Gets a collection of properties defined in the type.
public IList<PropertyDefinition> Properties { get; }
Property Value
SecurityDeclarations
Gets a collection of security declarations assigned to the member.
public IList<SecurityDeclaration> SecurityDeclarations { get; }
Property Value
Methods
CanAccessDefinition(IMemberDefinition)
Determines whether the provided definition can be accessed by the type.
public bool CanAccessDefinition(IMemberDefinition definition)
Parameters
definition
IMemberDefinitionThe definition to access.
Returns
- bool
true
if this type can accessdefinition
,false
otherwise.
GetBaseType()
Obtains the base type of the type definition.
protected virtual ITypeDefOrRef? GetBaseType()
Returns
- ITypeDefOrRef
The namespace.
Remarks
This method is called upon initialization of the BaseType property.
GetClassLayout()
Obtains the class layout of this type.
protected virtual ClassLayout? GetClassLayout()
Returns
- ClassLayout
The class layout.
Remarks
This method is called upon initialization of the ClassLayout property.
GetConstructor()
Finds the instance parameterless constructor this type defines.
public MethodDefinition? GetConstructor()
Returns
- MethodDefinition
The constructor, or
null
if none is present.
GetConstructor(SignatureComparer, params TypeSignature[])
Finds the instance constructor with the provided parameter types this type defines.
public MethodDefinition? GetConstructor(SignatureComparer comparer, params TypeSignature[] parameterTypes)
Parameters
comparer
SignatureComparerThe signature comparer to use when comparing the parameter types.
parameterTypes
TypeSignature[]An ordered list of types the parameters of the constructor should have.
Returns
- MethodDefinition
The constructor, or
null
if none is present.
GetConstructor(SignatureComparer, IList<TypeSignature>)
Finds the instance constructor with the provided parameter types this type defines.
public MethodDefinition? GetConstructor(SignatureComparer comparer, IList<TypeSignature> parameterTypes)
Parameters
comparer
SignatureComparerThe signature comparer to use when comparing the parameter types.
parameterTypes
IList<TypeSignature>An ordered list of types the parameters of the constructor should have.
Returns
- MethodDefinition
The constructor, or
null
if none is present.
GetConstructor(params TypeSignature[])
Finds the instance constructor with the provided parameter types this type defines.
public MethodDefinition? GetConstructor(params TypeSignature[] parameterTypes)
Parameters
parameterTypes
TypeSignature[]An ordered list of types the parameters of the constructor should have.
Returns
- MethodDefinition
The constructor, or
null
if none is present.
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.
GetDeclaringType()
Obtains the enclosing class of the type definition if available.
protected virtual TypeDefinition? GetDeclaringType()
Returns
- TypeDefinition
The enclosing type.
Remarks
This method is called upon initialization of the DeclaringType property.
GetEnumUnderlyingType()
When this type is an enum, extracts the underlying enum type.
public TypeSignature? GetEnumUnderlyingType()
Returns
- TypeSignature
The type, or
null
if none was found.
Remarks
To verify whether a type is an enum or not, use the IsEnum property.
Exceptions
- InvalidOperationException
Occurs when the type is not an enum.
GetEvents()
Obtains the collection of events that this type defines.
protected virtual IList<EventDefinition> GetEvents()
Returns
- IList<EventDefinition>
The events.
Remarks
This method is called upon initialization of the Events property.
GetFields()
Obtains the collection of fields that this type defines.
protected virtual IList<FieldDefinition> GetFields()
Returns
- IList<FieldDefinition>
The fields.
Remarks
This method is called upon initialization of the Fields property.
GetGenericParameters()
Obtains the list of generic parameters this member declares.
protected virtual IList<GenericParameter> GetGenericParameters()
Returns
- IList<GenericParameter>
The generic parameters
Remarks
This method is called upon initialization of the GenericParameters property.
GetInterfaces()
Obtains the list of interfaces this type implements.
protected virtual IList<InterfaceImplementation> GetInterfaces()
Returns
- IList<InterfaceImplementation>
The interfaces.
Remarks
This method is called upon initialization of the Interfaces property.
GetMethodImplementations()
Obtains the list of methods this type implements.
protected virtual IList<MethodImplementation> GetMethodImplementations()
Returns
- IList<MethodImplementation>
The method implementations.
Remarks
This method is called upon initialization of the MethodImplementations property.
GetMethods()
Obtains the collection of methods that this type defines.
protected virtual IList<MethodDefinition> GetMethods()
Returns
- IList<MethodDefinition>
The methods.
Remarks
This method is called upon initialization of the Methods property.
GetName()
Obtains the name of the type definition.
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 definition.
protected virtual Utf8String? GetNamespace()
Returns
- Utf8String
The namespace.
Remarks
This method is called upon initialization of the Namespace property.
GetNestedTypes()
Obtains the list of nested types that this type defines.
protected virtual IList<TypeDefinition> GetNestedTypes()
Returns
- IList<TypeDefinition>
The nested types.
Remarks
This method is called upon initialization of the NestedTypes property.
GetOrCreateStaticConstructor()
Gets or creates the static constructor that is executed when the CLR loads this type.
public MethodDefinition GetOrCreateStaticConstructor()
Returns
- MethodDefinition
The static constructor, or
null
if none is present.
Remarks
If the static constructor was not present in the type, it will be inserted as the first method in the type. This method can only be used when the type has already been added to the metadata image.
GetOrCreateStaticConstructor(ModuleDefinition?)
Gets or creates the static constructor that is executed when the CLR loads this type.
public MethodDefinition GetOrCreateStaticConstructor(ModuleDefinition? module)
Parameters
module
ModuleDefinitionThe image to use for creating the signature of the constructor if it is not present yet.
Returns
- MethodDefinition
The static constructor, or
null
if none is present.
Remarks
If the static constructor was not present in the type, it will be inserted as the first method in the type.
GetProperties()
Obtains the collection of properties that this type defines.
protected virtual IList<PropertyDefinition> GetProperties()
Returns
- IList<PropertyDefinition>
The properties.
Remarks
This method is called upon initialization of the Properties property.
GetSecurityDeclarations()
Obtains the list of security declarations assigned to the member.
protected virtual IList<SecurityDeclaration> GetSecurityDeclarations()
Returns
- IList<SecurityDeclaration>
The security declarations
Remarks
This method is called upon initialization of the SecurityDeclarations property.
GetStaticConstructor()
Finds the static constructor that is executed when the CLR loads this type.
public MethodDefinition? GetStaticConstructor()
Returns
- MethodDefinition
The static constructor, or
null
if none is present.
Implements(Utf8String?, Utf8String)
Determines whether the type implements a particular interface.
public bool Implements(Utf8String? ns, Utf8String name)
Parameters
ns
Utf8StringThe namespace of the type.
name
Utf8StringThe name of the type.
Returns
- bool
true
whether the current TypeDefinition implements the interface,false
otherwise.
Implements(string)
Determines whether the type implements a particular interface.
public bool Implements(string fullName)
Parameters
fullName
stringThe full name of the interface
Returns
- bool
true
whether the current TypeDefinition implements the interface,false
otherwise.
Implements(string?, string)
Determines whether the type implements a particular interface.
public bool Implements(string? ns, string name)
Parameters
Returns
- bool
true
whether the current TypeDefinition implements the interface,false
otherwise.
ImportWith(ReferenceImporter)
Imports the type definition using the provided reference importer object.
public ITypeDefOrRef ImportWith(ReferenceImporter importer)
Parameters
importer
ReferenceImporterThe reference importer to use.
Returns
- ITypeDefOrRef
The imported type.
InheritsFrom(Utf8String?, Utf8String)
Determines whether the type inherits from a particular type.
public bool InheritsFrom(Utf8String? ns, Utf8String name)
Parameters
ns
Utf8StringThe namespace of the type.
name
Utf8StringThe name of the type.
Returns
- bool
true
whether the current TypeDefinition inherits from the type,false
otherwise.
InheritsFrom(string)
Determines whether the type inherits from a particular type.
public bool InheritsFrom(string fullName)
Parameters
fullName
stringThe full name of the type
Returns
- bool
true
whether the current TypeDefinition inherits from the type,false
otherwise.
InheritsFrom(string?, string)
Determines whether the type inherits from a particular type.
public bool InheritsFrom(string? ns, string name)
Parameters
Returns
- bool
true
whether the current TypeDefinition inherits from the type,false
otherwise.
IsAccessibleFromType(TypeDefinition)
Determines whether the member can be accessed from the scope that is determined by the provided type.
public bool IsAccessibleFromType(TypeDefinition type)
Parameters
type
TypeDefinitionThe type defining the scope.
Returns
- bool
True if the scope of the provided type can access the member, false otherwise.
IsImportedInModule(ModuleDefinition)
Determines whether the descriptor of the member is fully imported in the provided module.
public bool IsImportedInModule(ModuleDefinition module)
Parameters
module
ModuleDefinitionThe 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.
ToString()
Returns a string that represents the current object.
public override string ToString()
Returns
- string
A string that represents the current object.
ToTypeReference()
Creates a new type reference to this type definition.
public TypeReference ToTypeReference()
Returns
- TypeReference
The type reference.
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
booltrue
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.