Expand Minimize
0 out of 1 rated this helpful - Rate this topic

GenericParameterAttributes Enumeration

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.Reflection
Assembly:  mscorlib (in mscorlib.dll)
[<FlagsAttribute>]
type GenericParameterAttributes
Member nameDescription
Supported by Portable Class LibrarySupported in .NET for Windows Store appsNoneThere are no special flags.
Supported by Portable Class LibrarySupported in .NET for Windows Store appsVarianceMaskSelects the combination of all variance flags. This value is the result of using logical OR to combine the following flags: Contravariant and Covariant.
Supported by Portable Class LibrarySupported in .NET for Windows Store appsCovariantThe 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.
Supported by Portable Class LibrarySupported in .NET for Windows Store appsContravariantThe generic type parameter is contravariant. A contravariant type parameter can appear as a parameter type in method signatures.
Supported by Portable Class LibrarySupported in .NET for Windows Store appsSpecialConstraintMaskSelects 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.
Supported by Portable Class LibrarySupported in .NET for Windows Store appsReferenceTypeConstraintA type can be substituted for the generic type parameter only if it is a reference type.
Supported by Portable Class LibrarySupported in .NET for Windows Store appsNotNullableValueTypeConstraintA type can be substituted for the generic type parameter only if it is a value type and is not nullable.
Supported by Portable Class LibrarySupported in .NET for Windows Store appsDefaultConstructorConstraintA type can be substituted for the generic type parameter only if it has a parameterless constructor.

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.

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Store apps

Supported in: Windows 8

Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Did you find this helpful?
(1500 characters remaining)
© 2013 Microsoft. All rights reserved.