GenericParameterAttributes Enumeration
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
Describes the constraints on a generic type parameter of a generic type or method.
This enumeration has a FlagsAttribute attribute that allows a bitwise combination of its member values.
Namespace: System.ReflectionAssembly: mscorlib (in mscorlib.dll)
| Member name | Description | |
|---|---|---|
| Contravariant | The generic type parameter is contravariant. A contravariant type parameter can appear as a parameter type in method signatures. | |
| Covariant | The generic type parameter is covariant. A covariant type parameter can appear as the result type of a method, the type of a read-only field, a declared base type, or an implemented interface. | |
| DefaultConstructorConstraint | A type can be substituted for the generic type parameter only if it has a parameterless constructor. | |
| None | There are no special flags. | |
| NotNullableValueTypeConstraint | A type can be substituted for the generic type parameter only if it is a value type and is not nullable. | |
| ReferenceTypeConstraint | A type can be substituted for the generic type parameter only if it is a reference type. | |
| SpecialConstraintMask | Selects the combination of all special constraint flags. This value is the result of using logical OR to combine the following flags: DefaultConstructorConstraint, ReferenceTypeConstraint, and NotNullableValueTypeConstraint. | |
| VarianceMask | Selects the combination of all variance flags. This value is the result of using logical OR to combine the following flags: Contravariant and Covariant. |
The members of the GenericParameterAttributes enumeration are divided into two groups, the variance group and the special constraints group. To test a GenericParameterAttributes value for variance flags, first perform a bitwise AND operation with VarianceMask. If the result is None, there are no variance flags. Similarly, use SpecialConstraintMask to test for constraint flags.
The following code example defines a generic type Test with two type parameters. The second type parameter has a base class constraint and a reference type constraint. When the program executes, the constraints are examined using the Type::GenericParameterAttributes property and the Type::GetGenericParameterConstraints method.
Note: |
|---|
To run this example, see Building examples that have static TextBlock controls for Windows Phone 8. |
Note: