Table of Contents

Interface IType

Namespace
ICSharpCode.Decompiler.TypeSystem
Assembly
ICSharpCode.Decompiler.dll

This interface represents a resolved type in the type system.

public interface IType : INamedElement, IEquatable<IType>
Inherited Members
Extension Methods

Remarks

A type is potentially - a type definition (ITypeDefinition, i.e. a class, struct, interface, delegate, or built-in primitive type) - a parameterized type (ParameterizedType, e.g. List<int>) - a type parameter (ITypeParameter, e.g. T) - an array (ArrayType) - a pointer (PointerType) - a managed reference (ByReferenceType) - one of the special types (UnknownType, NullType, Dynamic, UnboundTypeArgument)

The Kind property can be used to switch on the kind of a type.

IType uses the null object pattern: UnknownType serves as the null object. Methods or properties returning IType never return null unless documented otherwise.

Types should be compared for equality using the Equals(T) method. Identical types do not necessarily use the same object reference.

Properties

DeclaringType

Gets the parent type, if this is a nested type. Returns null for top-level types.

IType? DeclaringType { get; }

Property Value

IType

DirectBaseTypes

Gets the direct base types.

IEnumerable<IType> DirectBaseTypes { get; }

Property Value

IEnumerable<IType>

Returns the direct base types including interfaces

IsByRefLike

Gets whether this type is "ref-like": a ByReferenceType or "ref struct".

bool IsByRefLike { get; }

Property Value

bool

IsReferenceType

Gets whether the type is a reference type or value type.

bool? IsReferenceType { get; }

Property Value

bool?

true, if the type is a reference type. false, if the type is a value type. null, if the type is not known (e.g. unconstrained generic type parameter or type not found)

Kind

Gets the type kind.

TypeKind Kind { get; }

Property Value

TypeKind

Nullability

Gets the nullability annotation on this type.

Nullability Nullability { get; }

Property Value

Nullability

TypeArguments

Gets the type arguments passed to this type. If this type is a generic type definition that is not parameterized, this property returns the type parameters, as if the type was parameterized with its own type arguments (class C<T> { C<T> field; }).

IReadOnlyList<IType> TypeArguments { get; }

Property Value

IReadOnlyList<IType>

TypeParameterCount

Gets the number of type parameters.

int TypeParameterCount { get; }

Property Value

int

TypeParameters

Gets the type parameters. Returns an empty list if this type is not generic.

IReadOnlyList<ITypeParameter> TypeParameters { get; }

Property Value

IReadOnlyList<ITypeParameter>

Methods

AcceptVisitor(TypeVisitor)

Calls ITypeVisitor.Visit for this type.

IType AcceptVisitor(TypeVisitor visitor)

Parameters

visitor TypeVisitor

Returns

IType

The return value of the ITypeVisitor.Visit call

ChangeNullability(Nullability)

Creates a new type that is a copy of this type, with the changed nullability annotation.

IType ChangeNullability(Nullability newNullability)

Parameters

newNullability Nullability

Returns

IType

GetAccessors(Predicate<IMethod>?, GetMemberOptions)

Gets all accessors belonging to properties or events on this type.

IEnumerable<IMethod> GetAccessors(Predicate<IMethod>? filter = null, GetMemberOptions options = GetMemberOptions.None)

Parameters

filter Predicate<IMethod>

The filter used to select which members to return. The filter is tested on the original member definitions (before specialization).

options GetMemberOptions

Specified additional options for the GetMembers() operation.

Returns

IEnumerable<IMethod>

Remarks

Accessors are not returned by GetMembers() or GetMethods().

GetConstructors(Predicate<IMethod>?, GetMemberOptions)

Gets all instance constructors for this type.

IEnumerable<IMethod> GetConstructors(Predicate<IMethod>? filter = null, GetMemberOptions options = GetMemberOptions.IgnoreInheritedMembers)

Parameters

filter Predicate<IMethod>

The filter used to select which constructors to return. The filter is tested on the original method definitions (before specialization).

options GetMemberOptions

Specified additional options for the GetMembers() operation.

Returns

IEnumerable<IMethod>

Remarks

The result does not include static constructors. Constructors in base classes are not returned by default, as GetMemberOptions.IgnoreInheritedMembers is the default value.

For methods on parameterized types, type substitution will be performed on the method signature, and the appropriate SpecializedMethod will be returned.

GetDefinition()

Gets the underlying type definition. Can return null for types which do not have a type definition (for example arrays, pointers, type parameters).

ITypeDefinition? GetDefinition()

Returns

ITypeDefinition

GetDefinitionOrUnknown()

Gets the underlying type definition or UnkownType, if unknown. Can return null for types which do not have a type definition (for example arrays, pointers, type parameters).

ITypeDefinitionOrUnknown? GetDefinitionOrUnknown()

Returns

ITypeDefinitionOrUnknown

GetEvents(Predicate<IEvent>?, GetMemberOptions)

Gets all events that can be accessed on this type.

IEnumerable<IEvent> GetEvents(Predicate<IEvent>? filter = null, GetMemberOptions options = GetMemberOptions.None)

Parameters

filter Predicate<IEvent>

The filter used to select which events to return. The filter is tested on the original event definitions (before specialization).

options GetMemberOptions

Specified additional options for the GetMembers() operation.

Returns

IEnumerable<IEvent>

Remarks

For fields on parameterized types, type substitution will be performed on the event's return type, and the appropriate SpecializedEvent will be returned.

GetFields(Predicate<IField>?, GetMemberOptions)

Gets all fields that can be accessed on this type.

IEnumerable<IField> GetFields(Predicate<IField>? filter = null, GetMemberOptions options = GetMemberOptions.None)

Parameters

filter Predicate<IField>

The filter used to select which constructors to return. The filter is tested on the original field definitions (before specialization).

options GetMemberOptions

Specified additional options for the GetMembers() operation.

Returns

IEnumerable<IField>

Remarks

For fields on parameterized types, type substitution will be performed on the field's return type, and the appropriate SpecializedField will be returned.

GetMembers(Predicate<IMember>?, GetMemberOptions)

Gets all members that can be called on this type.

IEnumerable<IMember> GetMembers(Predicate<IMember>? filter = null, GetMemberOptions options = GetMemberOptions.None)

Parameters

filter Predicate<IMember>

The filter used to select which members to return. The filter is tested on the original member definitions (before specialization).

options GetMemberOptions

Specified additional options for the GetMembers() operation.

Returns

IEnumerable<IMember>

Remarks

The resulting list is the union of GetFields(), GetProperties(), GetMethods() and GetEvents(). It does not include constructors. For parameterized types, type substitution will be performed.

For generic methods, the remarks about ambiguous signatures from the GetMethods(Predicate<IMethod>?, GetMemberOptions) method apply here as well.

GetMethods(IReadOnlyList<IType>, Predicate<IMethod>?, GetMemberOptions)

Gets all generic methods that can be called on this type with the specified type arguments.

IEnumerable<IMethod> GetMethods(IReadOnlyList<IType> typeArguments, Predicate<IMethod>? filter = null, GetMemberOptions options = GetMemberOptions.None)

Parameters

typeArguments IReadOnlyList<IType>

The type arguments used for the method call.

filter Predicate<IMethod>

The filter used to select which methods to return. The filter is tested on the original method definitions (before specialization).

options GetMemberOptions

Specified additional options for the GetMembers() operation.

Returns

IEnumerable<IMethod>

Remarks

The result does not include constructors or accessors.

Type substitution will be performed on the method signature, creating a SpecializedMethod with the specified type arguments.

When the list of type arguments is empty, this method acts like the GetMethods() overload without the type arguments parameter - that is, it also returns generic methods, and the other overload's remarks about ambiguous signatures apply here as well.

GetMethods(Predicate<IMethod>?, GetMemberOptions)

Gets all methods that can be called on this type.

IEnumerable<IMethod> GetMethods(Predicate<IMethod>? filter = null, GetMemberOptions options = GetMemberOptions.None)

Parameters

filter Predicate<IMethod>

The filter used to select which methods to return. The filter is tested on the original method definitions (before specialization).

options GetMemberOptions

Specified additional options for the GetMembers() operation.

Returns

IEnumerable<IMethod>

Remarks

The result does not include constructors or accessors.

For methods on parameterized types, type substitution will be performed on the method signature, and the appropriate SpecializedMethod will be returned.

If the method being returned is generic, and this type is a parameterized type where the type arguments involve another method's type parameters, the resulting specialized signature will be ambiguous as to which method a type parameter belongs to. For example, "List[[``0]].GetMethods()" will return "ConvertAll(Converter`2[[``0, ``0]])".

If possible, use the other GetMethods() overload to supply type arguments to the method, so that both class and method type parameter can be substituted at the same time, so that the ambiguity can be avoided.

GetNestedTypes(IReadOnlyList<IType>, Predicate<ITypeDefinition>?, GetMemberOptions)

Gets inner classes (including inherited inner classes) that have typeArguments.Count additional type parameters.

IEnumerable<IType> GetNestedTypes(IReadOnlyList<IType> typeArguments, Predicate<ITypeDefinition>? filter = null, GetMemberOptions options = GetMemberOptions.None)

Parameters

typeArguments IReadOnlyList<IType>

The type arguments passed to the inner class

filter Predicate<ITypeDefinition>

The filter used to select which types to return. The filter is tested on the original type definitions (before parameterization).

options GetMemberOptions

Specified additional options for the GetMembers() operation.

Returns

IEnumerable<IType>

Remarks

Type parameters belonging to the outer class will have the value copied from the outer type if it is a parameterized type. Otherwise, those existing type parameters will be self-parameterized, and thus 'leaked' to the caller in the same way the GetMembers() method does not specialize members from an ITypeDefinition and 'leaks' type parameters in member signatures.

GetNestedTypes(Predicate<ITypeDefinition>?, GetMemberOptions)

Gets inner classes (including inherited inner classes).

IEnumerable<IType> GetNestedTypes(Predicate<ITypeDefinition>? filter = null, GetMemberOptions options = GetMemberOptions.None)

Parameters

filter Predicate<ITypeDefinition>

The filter used to select which types to return. The filter is tested on the original type definitions (before parameterization).

options GetMemberOptions

Specified additional options for the GetMembers() operation.

Returns

IEnumerable<IType>

Examples

class Base<T> {
	class Nested<X> {}
}
class Derived<A, B> : Base<B> {}

Derived[string,int].GetNestedTypes() = { Base`1+Nested`1[int, unbound] }
Derived.GetNestedTypes() = { Base`1+Nested`1[`1, unbound] }
Base[`1].GetNestedTypes() = { Base`1+Nested`1[`1, unbound] }
Base.GetNestedTypes() = { Base`1+Nested`1[`0, unbound] }

Remarks

If the nested type is generic, this method will return a parameterized type, where the additional type parameters are set to UnboundTypeArgument.

Type parameters belonging to the outer class will have the value copied from the outer type if it is a parameterized type. Otherwise, those existing type parameters will be self-parameterized, and thus 'leaked' to the caller in the same way the GetMembers() method does not specialize members from an ITypeDefinition and 'leaks' type parameters in member signatures.

GetProperties(Predicate<IProperty>?, GetMemberOptions)

Gets all properties that can be called on this type.

IEnumerable<IProperty> GetProperties(Predicate<IProperty>? filter = null, GetMemberOptions options = GetMemberOptions.None)

Parameters

filter Predicate<IProperty>

The filter used to select which properties to return. The filter is tested on the original property definitions (before specialization).

options GetMemberOptions

Specified additional options for the GetMembers() operation.

Returns

IEnumerable<IProperty>

Remarks

For properties on parameterized types, type substitution will be performed on the property signature, and the appropriate SpecializedProperty will be returned.

GetSubstitution()

Gets a type visitor that performs the substitution of class type parameters with the type arguments of this parameterized type. Returns TypeParameterSubstitution.Identity if the type is not parametrized.

TypeParameterSubstitution GetSubstitution()

Returns

TypeParameterSubstitution

VisitChildren(TypeVisitor)

Calls ITypeVisitor.Visit for all children of this type, and reconstructs this type with the children based on the return values of the visit calls.

IType VisitChildren(TypeVisitor visitor)

Parameters

visitor TypeVisitor

Returns

IType

A copy of this type, with all children replaced by the return value of the corresponding visitor call. If the visitor returned the original types for all children (or if there are no children), returns this.