This documentation is archived and is not being maintained.

GenericTypeParameterBuilder.SetGenericParameterAttributes Method

Sets the variance characteristics and special constraints of the generic parameter, such as the parameterless constructor constraint.

Namespace:  System.Reflection.Emit
Assembly:  mscorlib (in mscorlib.dll)

member SetGenericParameterAttributes : 
        genericParameterAttributes:GenericParameterAttributes -> unit 


Type: System.Reflection.GenericParameterAttributes
A bitwise combination of GenericParameterAttributes values that represent the variance characteristics and special constraints of the generic type parameter.

Special constraints can specify that any type assigned to the generic type parameter must have a default constructor, must be a reference type, or must be a value type.

Special constraints cannot be retrieved using methods of the GenericTypeParameterBuilder class. Once you have created the generic type that contains the type parameter, you can use its Type object to reflect the type parameters and their constraints. To get the type parameters of a completed generic type, use the Type.GetGenericArguments method. To get the special constraints for each type parameter, use the Type.GenericParameterAttributes property.

The GenericParameterAttributes enumeration values that refer to the variance characteristics of a type parameter are relevant only in languages that support covariance and contravariance, such as Microsoft intermediate language (MSIL). Visual Basic and C# currently do not support covariance and contravariance.

The following code example creates a generic type with two type parameters, the first of which is constrained to have a default constructor and to be a reference type, and saves them in the assembly GenericEmitExample1.dll. You can use the Ildasm.exe (MSIL Disassembler) to view the generated types. For a more detailed explanation of the steps involved in defining a dynamic generic type, see How to: Define a Generic Type with Reflection Emit.

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

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

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