Type.IsGenericParameter 속성

정의

현재 Type이 제네릭 형식 또는 메서드 정의의 형식 매개 변수를 나타내는지를 나타내는 값을 가져옵니다.

public:
 abstract property bool IsGenericParameter { bool get(); };
public:
 virtual property bool IsGenericParameter { bool get(); };
public abstract bool IsGenericParameter { get; }
public virtual bool IsGenericParameter { get; }
member this.IsGenericParameter : bool
Public MustOverride ReadOnly Property IsGenericParameter As Boolean
Public Overridable ReadOnly Property IsGenericParameter As Boolean

속성 값

Boolean

Type 개체가 제네릭 형식 정의나 메서드 정의의 형식 매개 변수를 나타내면 true이고, 그렇지 않으면 false입니다.

예제

다음 예제에서는 IsGenericParameter 속성을 사용하여 제네릭 형식의 제네릭 형식 매개 변수를 테스트합니다.

if ( t->IsGenericType )
{
   
   // If this is a generic type, display the type arguments.
   //
   array<Type^>^typeArguments = t->GetGenericArguments();
   Console::WriteLine( L"\tList type arguments ({0}):",
      typeArguments->Length );
   System::Collections::IEnumerator^ myEnum =
      typeArguments->GetEnumerator();
   while ( myEnum->MoveNext() )
   {
      Type^ tParam = safe_cast<Type^>(myEnum->Current);
      
      // If this is a type parameter, display its
      // position.
      //
      if ( tParam->IsGenericParameter )
      {
         Console::WriteLine(
            L"\t\t{0}\t(unassigned - parameter position {1})",
            tParam, tParam->GenericParameterPosition );
      }
      else
      {
         Console::WriteLine( L"\t\t{0}", tParam );
      }
   }
}
if (t.IsGenericType)
{
    // If this is a generic type, display the type arguments.
    //
    Type[] typeArguments = t.GetGenericArguments();

    Console.WriteLine("\tList type arguments ({0}):", 
        typeArguments.Length);

    foreach (Type tParam in typeArguments)
    {
        // If this is a type parameter, display its
        // position.
        //
        if (tParam.IsGenericParameter)
        {
            Console.WriteLine("\t\t{0}\t(unassigned - parameter position {1})",
                tParam,
                tParam.GenericParameterPosition);
        }
        else
        {
            Console.WriteLine("\t\t{0}", tParam);
        }
    }
}
If t.IsGenericType Then
    ' If this is a generic type, display the type arguments.
    '
    Dim typeArguments As Type() = t.GetGenericArguments()
    
    Console.WriteLine(vbTab & "List type arguments (" _
        & typeArguments.Length & "):")
    
    For Each tParam As Type In typeArguments
        ' If this is a type parameter, display its position.
        '
        If tParam.IsGenericParameter Then
            Console.WriteLine(vbTab & vbTab & tParam.ToString() _
                & vbTab & "(unassigned - parameter position " _
                & tParam.GenericParameterPosition & ")")
        Else
            Console.WriteLine(vbTab & vbTab & tParam.ToString())
        End If
    Next tParam
End If

설명

Type 제네릭 형식 매개 변수를 나타내는 개체는 GetGenericArguments Type 제네릭 형식 정의를 나타내는 개체의 메서드 또는 제네릭 메서드 정의를 나타내는 GetGenericArguments 개체의 메서드를 호출하여 가져올 수 MethodInfo 있습니다.

  • 제네릭 형식 또는 메서드 정의의 경우 IsGenericParameter 속성은 true 결과 배열의 모든 요소에 대해 를 반환합니다.

  • 닫힌 생성 형식 또는 메서드의 경우 속성은 메서드에서 IsGenericParameter false 반환된 배열의 모든 요소에 대해 를 GetGenericArguments 반환합니다.

  • 개방형 생성 형식 또는 메서드의 경우 배열의 일부 요소는 특정 형식일 수 있고 다른 요소는 형식 매개 변수일 수 있습니다. IsGenericParameterfalse는 형식에 대해 를 반환하고 true 형식 매개 변수에 대해 를 반환합니다. 속성에 대한 코드 예제는 ContainsGenericParameters 형식과 형식 매개 변수가 혼합된 제네릭 클래스를 보여 줍니다.

제네릭 리플렉션에 사용되는 용어의 고정 조건 목록은 IsGenericType 속성 설명을 참조하세요.

적용 대상

추가 정보