Open sandboxFocus

Interface ITypeParameter

Represents a generic type parameter of a method or type, such as T in List<T>.

Namespace: Metalama.Framework.Code
Assembly: Metalama.Framework.dll
Syntax
public interface ITypeParameter : INamedDeclaration, IDeclaration, IDiagnosticLocation, IMeasurable, IEquatable<IDeclaration>, IType, ICompilationElement, IDisplayable, IEquatable<IType>
Remarks

Type parameters are placeholders for types that are specified when a generic type or method is instantiated. They can have constraints that restrict which types can be used as type arguments.

In Metalama, type parameters are always bound. In a generic definition like List<T>, the type parameter T is bound to itself. In a constructed generic type like List<int>, the type parameter T is bound to int. Use the ResolvedType property to get the type to which a type parameter is bound.

Type parameters can have various constraints specified through properties like TypeKindConstraint, TypeConstraints, HasDefaultConstructorConstraint, and AllowsRefStruct.

Properties

Name Description
AllowsRefStruct

Gets a value indicating whether the type parameter has the allows ref struct anti-constraint.

HasDefaultConstructorConstraint

Gets a value indicating whether the type parameter has the new() constraint.

Index

Gets the zero-based position of the type parameter in the type parameter list.

IsConstraintNullable

Gets a value indicating whether the Class constraint has the nullable annotation (?). This property returns null if the TypeKindConstraint has a different value than Class or if the nullability of the type parameter has not been analyzed.

ResolvedType

Gets the concrete IType to which the type parameter is resolved, if the parent type or method is a generic instance. If it is a generic definition, returns the current instance.

TypeConstraints

Gets the type constraints of the type parameter, such as base class or interface constraints.

TypeKindConstraint

Gets the constraint on the kind of type, e.g. Class or Struct.

TypeParameterKind
Variance

Gets the kind variance: In, Out or None.

Methods

Name Description
StripNullabilityAnnotation()

Strips the nullability annotation from the current type, returning an unannotated version.

ToNonNullable()

Returns the non-nullable type from the current IType. If the current type is a non-nullable reference type, returns the current type. If the current type is a Nullable<T>, i.e. a nullable value type, returns the underlying type.

ToRef()

Gets a reference that can be used to identify the current declaration across different compilation versions.

Extension Methods

See Also