Open sandboxFocus

Interface IGeneric

Represents a generic declaration with type parameters, common to INamedType and IMethod.

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

In Metalama, and unlike System.Reflection, generic types and methods are always fully bound. In generic declarations, such as in typeof(List<>), type parameters are bound to themselves, i.e. the content of the TypeArguments and TypeParameters properties are identical.

Consider the type List<T>, where T is a type parameter. In the generic type instance List<int>, T is the type parameter and int is the type argument; the T parameter is bound to int. In the type definition List<T>, T is both the type parameter and the type argument, because T is bound to itself. The IsCanonicalGenericInstance property returns true when all type parameters are bound to themselves.

To create a generic instance from a generic definition, use MakeGenericInstance(IReadOnlyList<IType>) or the extension methods in GenericExtensions.

Properties

Name Description
IsCanonicalGenericInstance

Gets a value indicating whether all type parameters are bound to themselves, i.e. if the content of TypeArguments and TypeParameters are equal. This property returns true if the current declaration has no generic argument. For generic methods, this property returns false if the declaring type is generic but is not a canonical generic instance.

IsGeneric

Gets a value indicating whether this member has type parameters, regardless the fact that the containing type, if any, is generic.

TypeArguments

Gets the generic type arguments of the current type or method, which are the type values applied to the TypeParameters of the current type. The number of items in this list is always the same as in TypeParameters.

TypeParameters

Gets the type parameters of the current type or method.

Extension Methods

See Also