Interface IType
Represents a type declared in an application assembly, or declared in a third-party assembly and used by the application code.
public interface IType : ICodeElementParent, ICodeContainer, IUser, IMember, IAttributeTarget, ICodeElement, IUsed
- Inherited Members
- Extension Methods
Properties (70)
ABT
Gets the Association Between Classes for this type, computed as the number of members of others types it directly uses in the body of its child methods.
ushort? ABT { get; }
Property Value
- ushort?
null if this type is declared in a third-party assembly.
Otherwise returns this type ABT numeric value.
BaseClass
Gets the IType object representing the base class of this class, if any, otherwise gets null.
IType BaseClass { get; }
Property Value
Remarks
Interfaces or the class System.Object don't have a base class.
This property getter has a constant time complexity.
- See Also
BaseClasses
Gets a sequence of all base classes of this class. The sequence is empty if this type doesn't have any base class.
IEnumerable<IType> BaseClasses { get; }
Property Value
Remarks
Interfaces or the class System.Object don't have any base class.
This property getter has a O(this.DepthOfInheritance) time complexity.
- See Also
ClassConstructor
Gets the IMethod object representing this class constructor, if any, otherwise gets null.
IMethod ClassConstructor { get; }
Property Value
Remarks
This property getter has a O(this.Members.Count) time complexity.
Constructors
Gets a sequence of constructors of this type. The sequence doesn't contain class constructor.
IEnumerable<IMethod> Constructors { get; }
Property Value
Remarks
This property getter has a O(this.Members.Count) time complexity.
- See Also
ContainsMethodDependencyCycle
Gets a value indicating whether this type contains a dependency cycle between its MethodsAndConstructors. Gets null if this type is declared in a third-party assembly.
bool? ContainsMethodDependencyCycle { get; }
Property Value
- bool?
Remarks
The result of this property getter is lazy computed.
The first time it is called it has a O(this.MethodsAndConstructors.Count ^2) time complexity.
Further calls result in a constant time complexity.
CyclomaticComplexity
Gets a numeric nullable value measuring this type child methods additive source code complexity.
uint? CyclomaticComplexity { get; }
Property Value
- uint?
null if this type is declared in a third-party assembly.
null if this type has no method where IMethod.CyclomaticComplexity is available.
null if the PDB file of this type parent's assembly, hasen't been found.
null if the source code file path referenced from the PDB file cannot be found.
null if the source code of this type is written with a programming language different than C#.
Otherwise returns this type child methods additive source code complexity.
More information on this can be found at: Understanding NDepend Analysis Inputs
Remarks
Adapted to the Object-Oriented world, the IMethod.CyclomaticComplexity (CC) metric is also defined for classes and structures as the sum of its methods CC.
Availability:
A non-null numeric value is returned for types with methods where
DepthOfInheritance
Gets a numeric nullable value measuring this type's depth of inheritance.
ushort? DepthOfInheritance { get; }
Property Value
- ushort?
null if this type is declared in a third-party assembly.
null if this type is static or is an interface.
Otherwise returns this type DepthOfInheritance numeric value.
Remarks
The depth of inheritance for a class directly deriving from System.Object class is equal to 1.
The depth of inheritance for a structure is equal to 2 since it derives from System.ValueType that derives from System.Object.
The depth of inheritance for an enumeration is equal to 3 since it derives from System.Enum that derives from System.ValueType that derives from System.Object.
Recommendations:
Types where DepthOfInheritance is higher or equal than 6 might be hard to maintain. However this is not a rule since sometime your classes might inherit from third-party classes that have a high depth of inheritance.
For example, the average depth of inheritance for .NET Framework classes that derive from System.Windows.Forms.Control is 5.3.
DerivedTypes
Gets a sequence of all types derived from this type. The sequence is empty if this type has no derived type.
IEnumerable<IType> DerivedTypes { get; }
Property Value
Remarks
This property getter has a O(this.DerivedTypes.Count) time complexity.
- See Also
DirectDerivedTypes
Gets a sequence of types that derives directly from this type. The sequence is empty if this type has no derived type.
IEnumerable<IType> DirectDerivedTypes { get; }
Property Value
Remarks
This property getter has a O(this.DirectDerivedTypes.Count) time complexity.
- See Also
DirectNestedTypes
Gets a sequence of types nested in this type. The sequence doesn't contain types nested in types nested in this type.
IEnumerable<IType> DirectNestedTypes { get; }
Property Value
Remarks
This property getter has a O(this.TypesUsed.Count) time complexity.
Notice that for third-party nested types, the property IType.IsNested is set to true,
but the parent/nested relation is not resolved. Hence for third-party types, an empty sequence is returned by this property.
- See Also
ElementsThatITagAsAttribute
Returns a sequence of code elements that this type tags as an attribute. If this type is not an attribute or if no such element, returns an empty sequence.
IEnumerable<IAttributeTarget> ElementsThatITagAsAttribute { get; }
Property Value
Events
Gets a sequence of events of this type.
IEnumerable<IEvent> Events { get; }
Property Value
Fields
Gets a sequence of fields of this type.
IEnumerable<IField> Fields { get; }
Property Value
Remarks
This property getter has a O(this.Members.Count) time complexity.
- See Also
HasFinalizer
Gets a value indicating whether this type contains a finalizer method.
bool HasFinalizer { get; }
Property Value
ILCyclomaticComplexity
Gets a numeric nullable value measuring this type child methods additive IL code complexity.
uint? ILCyclomaticComplexity { get; }
Property Value
- uint?
null if this type is declared in a third-party assembly.
null if this type has no method with IMethod.ILCyclomaticComplexity available.
Otherwise returns this type child methods additive IL code complexity.
Remarks
Adapted to the Object-Oriented world, the IMethod.ILCyclomaticComplexity (ILCC) metric is also defined for classes and structures as the sum of its methods ILCC.
Availability:
A non-null numeric value is returned for types with methods where IMethod.ILCyclomaticComplexity is available.
InstanceFields
Gets a sequence of non-static fields of this type.
IEnumerable<IField> InstanceFields { get; }
Property Value
Remarks
This property getter has a O(this.Members.Count) time complexity.
- See Also
InstanceMembers
Gets a sequence of non-static members of this type. The sequence contains non-static constructors, non-static methods and non-static fields, but doesn't contain nested types. See DirectNestedTypes and NestedTypes.
IEnumerable<IMember> InstanceMembers { get; }
Property Value
Remarks
This property getter has a O(this.Members.Count) time complexity.
- See Also
InstanceMethods
Gets a sequence of non-static methods of this type. The sequence doesn't contain non-static constructors but contain non-static properties getters and setters, and non-static events adders and removers.
IEnumerable<IMethod> InstanceMethods { get; }
Property Value
Remarks
This property getter has a O(this.Members.Count) time complexity.
- See Also
InstanceMethodsAndConstructors
Gets a sequence of non-static methods and constructors of this type. The sequence also contains non-static properties getters and setters, and non-static events adders and removers.
IEnumerable<IMethod> InstanceMethodsAndConstructors { get; }
Property Value
Remarks
This property getter has a O(this.Members.Count) time complexity.
- See Also
InstanceMethodsAndContructors
Gets a sequence of non-static methods and constructors of this type. The sequence also contains non-static properties getters and setters, and non-static events adders and removers.
[Obsolete("typo in InstanceMethodsAndContructors, consider using InstanceMethodsAndConstructors")]
IEnumerable<IMethod> InstanceMethodsAndContructors { get; }
Property Value
Remarks
This property getter has a O(this.Members.Count) time complexity.
- See Also
InterfacesImplemented
Gets a sequence of interfaces implemented by this type. The sequence returned is empty if this type doesn't implement any interface.
IEnumerable<IType> InterfacesImplemented { get; }
Property Value
Remarks
This property getter has a O(this.InterfacesImplemented.Count) time complexity.
- See Also
IsAbstract
Gets a value indicating whether this type is an abstract class or an interface.
bool IsAbstract { get; }
Property Value
IsAttributeClass
Gets a value indicating whether this type is an attribute class, deriving from System.Attribute.
bool IsAttributeClass { get; }
Property Value
IsClass
Gets a value indicating whether this type is a class.
bool IsClass { get; }
Property Value
IsDelegate
Gets a value indicating whether this type is a delegate class, deriving from System.MulticastDelegate.
bool IsDelegate { get; }
Property Value
IsEnumeration
Gets a value indicating whether this type is an enumeration.
bool IsEnumeration { get; }
Property Value
IsExceptionClass
Gets a value indicating whether this type is an exception class, deriving from System.Exception.
bool IsExceptionClass { get; }
Property Value
IsGeneric
Gets a value indicating whether this type is a generic type.
bool IsGeneric { get; }
Property Value
IsImmutable
Gets a value indicating whether this type is immutable. A type is considered as immutable if its instance fields cannot be modified once an instance has been built by a constructor.
bool IsImmutable { get; }
Property Value
Remarks
- A stateless type (i.e a type without any instance field) is considered as immutable.
- A type with at least one non-private instance field is considered as mutable, because such a field can be eventually modified outside the type.
- A class that derives directly or indirectly from a mutable type is considered as mutable.
- Enumerations, static types, types defined in third-party assemblies and delegate classes are never considered as immutable. Although these types might match the definition of immutability, considering them as immutable would introduce noise when searching for immutable types.
- Particularly, classes that derive directly or indirectly from a class defined in a third-party assembly that is not the System.Object class, is never considered as immutable.
- Using the readonly C# keyword (ReadOnly in VB.NET) on your own instance field is a good way to achieve immutability.
- Notice that if a type T has some instance fields that are of reference type, the object pointed by such a reference might be modified without breaking the immutability of T. We are talking of shallow immutability.
As .NET framework designers considered that the immutability of the class System.String can be broken using advanced means such as reflection or unsafe code, you should consider that using the C# keyword ref or reflection or unsafe code are advanced means to break immutability of your own types.
Immutable types are especially useful when you have to deal with multi-threading application. Indeed, accesses to instances of immutable types don’t need to be synchronized because such objects can’t be modified; hence all accesses are read-only accesses.
To enforce your classes and structures immutability, see the attribute class ImmutableAttribute.
IsInterface
Gets a value indicating whether this type is an interface.
bool IsInterface { get; }
Property Value
IsNested
Gets a value indicating whether this type is nested in a parent type.
bool IsNested { get; }
Property Value
IsReadOnly
Gets a value indicating whether this type is declared with the C# keyword readonly.
bool IsReadOnly { get; }
Property Value
Remarks
So far only structures can be declared as readonly. Doing so leads the C# compiler and the JIT to perform some low-level optimizations.
IsRecord
Gets a value indicating whether this type is a record class, defined with the C# keyword record.
bool IsRecord { get; }
Property Value
IsSealed
Gets a value indicating whether this class is declared with the sealed keyword in C#, NotInheritable keyword in VB.NET.
bool IsSealed { get; }
Property Value
Remarks
Structures and necessarily marked as sealed.
IsSerializable
Gets a value indicating whether this type is serializable.
bool IsSerializable { get; }
Property Value
IsStructure
Gets a value indicating whether this type is a structure.
bool IsStructure { get; }
Property Value
IsTestClass
Gets a value indicating whether this type is a test class: a non-abstract class that declares or inherits at least one IsTestMethod method, or that is tagged with a test class attribute of a supported test framework, like [TestClass] or [TestFixture].
bool IsTestClass { get; }
Property Value
Remarks
This value is not persisted in the analysis result, it is inferred both at analysis time and when loading an analysis result.
- See Also
IsTypeForwarded
Returns a value indicating if this type is defined through the attribute TypeForwardedToAttribute.
bool IsTypeForwarded { get; }
Property Value
Remarks
If true is returned the property TypeForwardedDeclAssemblyName returns the name of the assembly that contains the declaration of this type.
IsUnion
Gets a value indicating whether this type is a union, defined with the C# 15 keyword union and tagged by the compiler with System.Runtime.CompilerServices.UnionAttribute.
bool IsUnion { get; }
Property Value
IsUsedFromAssemblyAttributes
Gets a value indicating whether this type is used from an attribute tagging an assembly.
bool IsUsedFromAssemblyAttributes { get; }
Property Value
Remarks
This state has been introduced to avoid considering a type as not used anywhere when it is only used from an assembly attribute, in situations like:
- [assembly: MyAttribute(typeof(Foo))] or
- [assembly: MyGenericAttribute<Foo>]
IsUsingBoxing
Gets a value indicating whether this type contains at least a method with an IL body that uses the box IL instruction.
bool IsUsingBoxing { get; }
Property Value
IsUsingPinning
Gets a value indicating whether this type contains at least a method that contains unsafe code that is using pinning.
bool IsUsingPinning { get; }
Property Value
Remarks
VB.NET does not support unsafe code but C# does.
In C#, pinning is generated through the fixed keyword.
IsUsingPointers
Gets a value indicating whether this type contains at least a method that contains unsafe code that is using some pointers.
bool IsUsingPointers { get; }
Property Value
Remarks
VB.NET does not support unsafe code but C# does.
IsUsingUnboxing
Gets a value indicating whether this type contains at least a method with an IL body that uses the unbox IL instruction.
bool IsUsingUnboxing { get; }
Property Value
IsVisibleOnlyInFile
Gets a value indicating whether this type is declared with the C# keyword file.
bool IsVisibleOnlyInFile { get; }
Property Value
LCOM
Gets a numeric nullable value assessing the class members cohesion, through the standard Lack of Cohesion Of Methods code metric.
float? LCOM { get; }
Property Value
- float?
null if this type is declared in a third-party assembly.
null if this type is an interface or an enumeration.
Otherwise returns this type LCOM numeric value.
Remarks
The single responsibility principle states that a class should not have more than one reason to change. Such a class is said to be cohesive.
A high LCOM value generally pinpoints a poorly cohesive class. There are two LCOM metrics.
- The LCOM takes its values in the range [0-1].
- The LCOM HS defined by LCOMHS (HS stands for Henderson-Sellers) takes its values in the range [0-2]. A LCOM HS value highest than 1 should be considered alarming.
- LCOM = 1 - (sum(MF)/MF)
- LCOM HS = (M - sum(MF)/F)(M-1)
- M is the number of methods in class (both static and instance methods are counted, it includes also constructors, properties getters/setters, events add/remove methods).
- F is the number of instance fields in the class.
- MF is the number of methods of the class accessing a particular instance field.
- Sum(MF) is the sum of MF over all instance fields of the class.
Recommendations:
Types where LCOM > 0.8 and NbFields > 10 and NbMethods >10 might be problematic. However, it is difficult to avoid such non-cohesive types.
Types where LCOMHS > 1.0 and NbFields > 10 and NbMethods >10 should be avoided. Note that this constraint is stronger (hence easier to satisfy) than the constraint types where LCOM > 0.8 and NbFields > 10 and NbMethods >10.
LCOMHS
Gets a numeric nullable value assessing the class members cohesion, through the standard Lack of Cohesion Of Methods Henderson-Sellers code metric.
float? LCOMHS { get; }
Property Value
- float?
null if this type is declared in a third-party assembly.
null if this type is an interface or an enumeration.
Otherwise returns this type LCOMHS numeric value.
Remarks
See the LCOM code metric definition for detailled explanations on the Lack of Cohesion Of Methods Henderson-Sellers code metric.
Members
Gets a sequence of members of this type. The sequence contains constructors, methods and fields, but doesn't contain nested types. See DirectNestedTypes and NestedTypes.
IEnumerable<IMember> Members { get; }
Property Value
Remarks
This property getter has a O(this.Members.Count) time complexity.
- See Also
Methods
Gets a sequence of methods of this type. The sequence doesn't contain constructors nor class constructors but contain properties getters and setters, and events adders and removers.
IEnumerable<IMethod> Methods { get; }
Property Value
Remarks
This property getter has a O(this.Members.Count) time complexity.
- See Also
MethodsAndConstructors
Gets a sequence of methods and constructors of this type. The sequence also contains properties getters and setters, and events adders and removers.
IEnumerable<IMethod> MethodsAndConstructors { get; }
Property Value
Remarks
This property getter has a O(this.Members.Count) time complexity.
- See Also
MethodsAndContructors
Gets a sequence of methods and constructors of this type. The sequence also contains properties getters and setters, and events adders and removers.
[Obsolete("typo in MethodsAndContructors, consider using MethodsAndConstructors")]
IEnumerable<IMethod> MethodsAndContructors { get; }
Property Value
Remarks
This property getter has a O(this.Members.Count) time complexity.
- See Also
NbChildren
Gets a numeric nullable value counting this class's number of derived classes, or this interface number of implementer types.
ushort? NbChildren { get; }
Property Value
- ushort?
null if this type is declared in a third-party assembly.
null if this type is static, is a structure or is an enumeration.
Otherwise returns this type NbChildren numeric value.
NbInterfacesImplemented
Gets a numeric value counting this class's number of implemented interfaces, or this interface number of extended interfaces.
ushort NbInterfacesImplemented { get; }
Property Value
Remarks
For derived class, the sum of interfaces implemented by base class(es) is also counted.
NbTypesUsed
Gets the number of types this type is using. Gets null if this type is declared in a third-party assembly.
uint? NbTypesUsed { get; }
Property Value
- uint?
NbTypesUsingMe
Gets the number of types that use this type.
uint NbTypesUsingMe { get; }
Property Value
NestedTypes
Gets a sequence of types nested in this type, or nested in a type nested in this type (recursive).
IEnumerable<IType> NestedTypes { get; }
Property Value
Remarks
This property getter has a O(this.TypesUsed.Count) time complexity.
Notice that for third-party nested types, the property IType.IsNested is set to true,
but the parent/nested relation is not resolved. Hence for third-party types, an empty sequence is returned by this property.
- See Also
OutterTypes
Gets a sequence of parent type(s) in which this type is nested.
IEnumerable<IType> OutterTypes { get; }
Property Value
Remarks
If this type is not nested returns an empty sequence.
The first type in sequence is the type returned by this.ParentType.
If the parent type is also nested, the second type in sequence if its parent type and so on.
Properties
Gets a sequence of properties of this type.
IEnumerable<IProperty> Properties { get; }
Property Value
Rank
Gets a numeric nullable value assessing this type rank, computed by the original Google Parge Rank algorithm.
float? Rank { get; }
Property Value
- float?
null if this type is declared in a third-party assembly.
Otherwise returns this type Rank numeric value.
Remarks
When discovering a legacy application, type ranking naturally sorts application types by an order of importance. Hence this code metric can help focusing on most relevant types first.
A homothety of center 0.15 is applied to make it so that the average of all application types.Rank is 1.
Recommendations:
Types with high rank should be more carefully tested because bugs in such types will likely be more catastrophic.
SizeOfInst
Gets a numeric nullable value measuring this type's instance object footprint, measured in bytes.
ushort? SizeOfInst { get; }
Property Value
- ushort?
null if this type is declared in a third-party assembly.
null if this type is static or is an interface.
Otherwise returns this type SizeOfInst numeric value.
Remarks
SizeOfInst for a class or a structure is defined as the sum of IField.SizeOfInst values of its fields plus the size of instances of its base class.
SizeOfInst for a generic type might be erroneous because we cannot statically know the footprint of parameter types (except when they have the class constraint).
SizeOfInst for an enumeration is equal to the size of instances of the underlying numeric primitive type. It is computed from the enumeration's value__ instance field (all enumerations have such a field when compiled in IL).
SizeOfInst for a static class or an interface is null.
Recommendations:
Types where SizeOfInst is higher than 64 might degrade performance (depending on the number of instances created at runtime) and might be hard to maintain.
However this is not a rule since sometime there are no alternatives. For example, the SizeOfInst value for the System.Net.NetworkInformation.SystemIcmpV6Statistics .NET framework class is 2064 bytes.
Non-static and non-generic types where SizeOfInst is equal to 0 indicate stateless types that might eventually be turned into static classes.
StaticFields
Gets a sequence of static fields of this type.
IEnumerable<IField> StaticFields { get; }
Property Value
Remarks
This property getter has a O(this.Members.Count) time complexity.
- See Also
StaticMembers
Gets a sequence of static members of this type. The sequence contains the class constructor (if any), static methods and fields, but doesn't contain nested types. See DirectNestedTypes and NestedTypes.
IEnumerable<IMember> StaticMembers { get; }
Property Value
Remarks
This property getter has a O(this.Members.Count) time complexity.
- See Also
StaticMethods
Gets a sequence of static methods of this type. The sequence doesn't contain the class constructor (if any) but contain static properties getters and setters, and static events adders and removers.
IEnumerable<IMethod> StaticMethods { get; }
Property Value
Remarks
This property getter has a O(this.Members.Count) time complexity.
- See Also
TagsWithMeAsAttribute
Returns a sequence of IAttributeTag with this type as IAttributeTag.AttributeType.
IEnumerable<IAttributeTag> TagsWithMeAsAttribute { get; }
Property Value
TypeForwardedDeclAssemblyName
If this type is defined through the attribute TypeForwardedToAttribute, returns the name of the assembly that contains the declaration of this type. Else returns null.
string TypeForwardedDeclAssemblyName { get; }
Property Value
TypesThatImplementMe
If this type is an interface, gets a sequence of types implementing this interface, otherwise gets an empty sequence.
IEnumerable<IType> TypesThatImplementMe { get; }
Property Value
Remarks
This property getter has a O(this.TypesUsingMe.Count) time complexity.
- See Also
TypesUsed
Gets a sequence of types that this type is using. If this type is declared in a third-party assembly, gets an empty sequence.
IEnumerable<IType> TypesUsed { get; }
Property Value
Remarks
This property getter has a O(this.TypesUsed.Count) time complexity.
- See Also
TypesUsingMe
Gets a sequence of types that are using this type.
IEnumerable<IType> TypesUsingMe { get; }
Property Value
Remarks
This property getter has a O(this.TypesUsingMe.Count) time complexity.
- See Also
UnionCaseTypes
If this type IsUnion, gets its case types in declaration order, else gets an empty sequence. For example union Pet(Cat, Dog, Bird) gets the types Cat, Dog and Bird.
IEnumerable<IType> UnionCaseTypes { get; }
Property Value
Remarks
A generic case type is returned as its generic type definition, once: the cases IEnumerable<int> and IEnumerable<double> both get the single type IEnumerable<T>. An array case gets its element type. A case that is a type parameter of the union, like T in union OneOrMore<T>(T, IEnumerable<T>), gets no type. The case types are inferred from the constructors the compiler generates for the union, one per case, matched by name against the types the union uses. Hence the sequence is empty for a union defined in a third-party assembly, and when the union uses two types with the same name in two namespaces, both can be returned for one case.
Methods (3)
DepthOfDeriveFrom(IType)
Returns a nullable numeric value equals to this type depth of inheritance, relative to baseClass. Returns null if this type doesn't derive from baseClass.
ushort? DepthOfDeriveFrom(IType baseClass)
Parameters
baseClassITypeThe base class.
Returns
Remarks
For any type T, T.DepthOfDeriveFrom(T) returns 0.
This property getter has a O(this.DepthOfInheritance) time complexity.
- See Also
DeriveFrom(IType)
Returns a value indicating whether this type derives directly or indirectly from baseClass.
bool DeriveFrom(IType baseClass)
Parameters
baseClassITypeThe base class to derive from.
Returns
Remarks
For any type T, T.DeriveFrom(T) returns false.
This property getter has a O(this.DepthOfInheritance) time complexity.
- See Also
Implement(IType)
Returns a value indicating whether this type implements interface.
bool Implement(IType @interface)
Parameters
interfaceITypeThe interface to implement.
Returns
Remarks
This method has a constant time complexity.
- See Also