|
이 문서는 기계로 번역한 것입니다. 원본 텍스트를 보려면 포인터를 문서의 문장 위로 올리십시오. 추가 정보
|
번역
원본
|
GenericParameterAttributes 열거형
.NET Framework 4.5
이 열거형에는 멤버 값을 비트로 조합할 수 있는 FlagsAttribute 특성이 있습니다.
네임스페이스: System.Reflection
어셈블리: mscorlib(mscorlib.dll)
| 멤버 이름 | 설명 | |
|---|---|---|
![]() ![]() | None | |
![]() ![]() | VarianceMask | |
![]() ![]() | Covariant | |
![]() ![]() | Contravariant | |
![]() ![]() | SpecialConstraintMask | |
![]() ![]() | ReferenceTypeConstraint | |
![]() ![]() | NotNullableValueTypeConstraint | |
![]() ![]() | DefaultConstructorConstraint |
using System; using System.Reflection; // Define a sample interface to use as an interface constraint. public interface ITest {} // Define a base type to use as a base class constraint. public class Base {} // Define the generic type to examine. The first generic type parameter, // T, derives from the class Base and implements ITest. This demonstrates // a base class constraint and an interface constraint. The second generic // type parameter, U, must be a reference type (class) and must have a // default constructor (new()). This demonstrates special constraints. // public class Test<T,U> where T : Base, ITest where U : class, new() {} // Define a type that derives from Base and implements ITest. This type // satisfies the constraints on T in class Test. public class Derived : Base, ITest {} public class Example { public static void Main() { // To get the generic type definition, omit the type // arguments but retain the comma to indicate the number // of type arguments. // Type def = typeof(Test<,>); Console.WriteLine("\r\nExamining generic type {0}", def); // Get the type parameters of the generic type definition, // and display them. // Type[] defparams = def.GetGenericArguments(); foreach (Type tp in defparams) { Console.WriteLine("\r\nType parameter: {0}", tp.Name); Console.WriteLine("\t{0}", ListGenericParameterAttributes(tp)); // List the base class and interface constraints. The // constraints are returned in no particular order. If // there are no class or interface constraints, an empty // array is returned. // Type[] tpConstraints = tp.GetGenericParameterConstraints(); foreach (Type tpc in tpConstraints) { Console.WriteLine("\t{0}", tpc); } } } // List the variance and special constraint flags. // private static string ListGenericParameterAttributes(Type t) { string retval; GenericParameterAttributes gpa = t.GenericParameterAttributes; GenericParameterAttributes variance = gpa & GenericParameterAttributes.VarianceMask; // Select the variance flags. if (variance == GenericParameterAttributes.None) retval = "No variance flag;"; else { if ((variance & GenericParameterAttributes.Covariant) != 0) retval = "Covariant;"; else retval = "Contravariant;"; } // Select GenericParameterAttributes constraints = gpa & GenericParameterAttributes.SpecialConstraintMask; if (constraints == GenericParameterAttributes.None) retval += " No special constraints"; else { if ((constraints & GenericParameterAttributes.ReferenceTypeConstraint) != 0) retval += " ReferenceTypeConstraint"; if ((constraints & GenericParameterAttributes.NotNullableValueTypeConstraint) != 0) retval += " NotNullableValueTypeConstraint"; if ((constraints & GenericParameterAttributes.DefaultConstructorConstraint) != 0) retval += " DefaultConstructorConstraint"; } return retval; } } /* This example produces the following output: Examining generic type Test`2[T,U] Type parameter: T No variance flag; no special constraints. Base ITest Type parameter: U No variance flag; ReferenceTypeConstraint DefaultConstructorConstraint */
Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008(서버 코어 역할은 지원되지 않음), Windows Server 2008 R2(서버 코어 역할은 SP1 이상에서 지원, Itanium은 지원되지 않음)
.NET Framework에서 모든 플랫폼의 전체 버전을 지원하지는 않습니다. 지원되는 버전의 목록을 보려면 .NET Framework 시스템 요구 사항을 참조하십시오.

