Type.IsGenericTypeDefinition プロパティとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > Type.IsGenericTypeDefinition プロパティの意味・解説 

Type.IsGenericTypeDefinition プロパティ

メモ : このプロパティは、.NET Framework version 2.0新しく追加されたものです。

現在の Type が、他のジェネリック型構築できるジェネリック型の定義を表しているかどうかを示す値を取得します

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Overridable ReadOnly
 Property IsGenericTypeDefinition As Boolean
Dim instance As Type
Dim value As Boolean

value = instance.IsGenericTypeDefinition
public virtual bool IsGenericTypeDefinition
 { get; }
public:
virtual property bool IsGenericTypeDefinition {
    bool get ();
}
/** @property */
public boolean get_IsGenericTypeDefinition ()
public function get IsGenericTypeDefinition
 () : boolean

プロパティ
Type オブジェクトジェネリック型定義表している場合trueそれ以外場合false

解説解説
使用例使用例

型がジェネリック型定義であるかどうかなど、型に関する情報次の例に示します構築型、ジェネリック型定義、および通常のに対して情報表示されています。

Imports System
Imports System.Reflection
Imports System.Collections.Generic
Imports Microsoft.VisualBasic

Public Class Test
    Private Shared Sub DisplayGenericTypeInfo(ByVal
 t As Type) 
        Console.WriteLine(vbCrLf & t.ToString())
        
        Console.WriteLine(vbTab & "Is this a generic type
 definition? " _
            & t.IsGenericTypeDefinition)
        
        Console.WriteLine(vbTab & "Is it a generic type? "
 _
            & t.IsGenericType)
        
        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
    
    End Sub 
    
    
    Public Shared Sub Main()
 
        Console.WriteLine(vbCrLf & "--- Display information
 about a constructed type, its")
        Console.WriteLine("    generic type definition, and an
 ordinary type.")
        
        ' Create a Dictionary of Test objects, using strings for the
        ' keys.       
        Dim d As New Dictionary(Of
 String, Test)()

        DisplayGenericTypeInfo(d.GetType())
        DisplayGenericTypeInfo(d.GetType().GetGenericTypeDefinition())
        
        ' Display information for an ordinary type.
        DisplayGenericTypeInfo(GetType(String))
    
    End Sub 'Main
End Class 'Test

' This example produces the following output:
'
'--- Display information about a constructed type, its
'    generic type definition, and an ordinary type.
'
'System.Collections.Generic.Dictionary[System.String, Test]
'        Is this a generic type definition? False
'        Is it a generic type? True
'        List type arguments (2):
'                System.String
'                Test
'
'System.Collections.Generic.Dictionary[TKey,TValue]
'        Is this a generic type definition? True
'        Is it a generic type? True
'        List type arguments (2):
'                TKey    (unassigned - parameter position 0)
'                TValue  (unassigned - parameter position 1)
'
'System.String
'        Is this a generic type definition? False
'        Is it a generic type? False
using System;
using System.Reflection;
using System.Collections.Generic;

public class Test
{
    private static void
 DisplayGenericTypeInfo(Type t)
    {
        Console.WriteLine("\r\n{0}", t);

        Console.WriteLine("\tIs this a generic type definition?
 {0}", 
            t.IsGenericTypeDefinition);

        Console.WriteLine("\tIs it a generic type? {0}", 
            t.IsGenericType);

        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);
                }
            }
        }
    }

    public static void Main()
    {
        Console.WriteLine("\r\n--- Display information about a constructed type,
 its");
        Console.WriteLine("    generic type definition, and an ordinary type.");

        // Create a Dictionary of Test objects, using strings for the
        // keys.       
        Dictionary<string, Test> d = new
 Dictionary<string, Test>();

        // Display information for the constructed type and its generic
        // type definition.
        DisplayGenericTypeInfo(d.GetType());
        DisplayGenericTypeInfo(d.GetType().GetGenericTypeDefinition());

        // Display information for an ordinary type.
        DisplayGenericTypeInfo(typeof(string));
    }
}

/* This example produces the following output:

--- Display information about a constructed type, its
    generic type definition, and an ordinary type.

System.Collections.Generic.Dictionary[System.String,Test]
        Is this a generic type definition? False
        Is it a generic type? True
        List type arguments (2):
                System.String
                Test

System.Collections.Generic.Dictionary[TKey,TValue]
        Is this a generic type definition? True
        Is it a generic type? True
        List type arguments (2):
                TKey    (unassigned - parameter position 0)
                TValue  (unassigned - parameter position 1)

System.String
        Is this a generic type definition? False
        Is it a generic type? False
 */
using namespace System;
using namespace System::Reflection;
using namespace System::Collections::Generic;

public ref class Test
{
private:
   static void DisplayGenericTypeInfo( Type^
 t )
   {
      Console::WriteLine( L"\r\n{0}", t );
      Console::WriteLine( L"\tIs this a generic type definition?
 {0}",
         t->IsGenericTypeDefinition );
      Console::WriteLine( L"\tIs it a generic type? {0}",
         t->IsGenericType );
      
      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 );
            }
         }
      }
   }


public:
   static void Main()
   {
      Console::Write( L"\r\n--- Display information about a " );
      Console::WriteLine( L"constructed type, its" );
      Console::WriteLine( L"    generic type definition, and an ordinary type."
 );
      
      // Create a Dictionary of Test objects, using strings for the
      // keys.
      Dictionary< String^,Test^ >^ d = gcnew Dictionary< String^,Test^ >;
      
      // Display information for the constructed type and its generic
      // type definition.
      DisplayGenericTypeInfo( d->GetType() );
      DisplayGenericTypeInfo( d->GetType()->GetGenericTypeDefinition() );
      
      // Display information for an ordinary type.
      DisplayGenericTypeInfo( String::typeid );
   }

};

int main()
{
   Test::Main();
}

/* This example produces the following output:

--- Display information about a constructed type, its
    generic type definition, and an ordinary type.

System.Collections.Generic.Dictionary[System.String,Test]
        Is this a generic type definition? False
        Is it a generic type? True
        List type arguments (2):
                System.String
                Test

System.Collections.Generic.Dictionary[TKey,TValue]
        Is this a generic type definition? True
        Is it a generic type? True
        List type arguments (2):
                TKey    (unassigned - parameter position 0)
                TValue  (unassigned - parameter position 1)

System.String
        Is this a generic type definition? False
        Is it a generic type? False
 */
import System.*;
import System.Reflection.*;
import System.Collections.Generic.*;

public class Test
{
    private static void
 DisplayGenericTypeInfo(Type t)
    {
        Console.WriteLine("\r\n{0}", t);
        Console.WriteLine("\tIs this a generic type definition?
 {0}",
            (System.Boolean)t.get_IsGenericTypeDefinition());
        Console.WriteLine("\tDoes it have generic arguments? {0}",
            (System.Boolean)t.get_IsGenericType());
        if (t.get_IsGenericType()) {
            // If this is a generic type, display the type arguments.
            Type typeArguments[] = t.GetGenericArguments();
            Console.WriteLine("\tList type arguments ({0}):",
                (Int32)typeArguments.get_Length());
            for (int iCtr = 0; iCtr < typeArguments.get_Length();
 iCtr++) {
                Type tParam = typeArguments[iCtr];
                // If this is a type parameter, display its
                // position.
                
                if (tParam.get_IsGenericParameter()) {
                    Console.WriteLine("\t\t{0}\t(unassigned - parameter "
                        + "position {1})", tParam, 
                        (Int32)tParam.get_GenericParameterPosition());
                }
                else {
                    Console.WriteLine("\t\t{0}", tParam);
                }
            }
        }
    } //DisplayGenericTypeInfo

    public static void main(String[]
 args)
    {
        Console.WriteLine("\r\n--- Display information about a "
            + "constructed type, its");
        Console.WriteLine("    generic type definition, and an ordinary type.");
        // Create a Dictionary of Test objects, using strings for the
        // keys.       
        Dictionary<String,Test> d = new Dictionary<String
,Test>();
        // Display information for the constructed type and its generic
        // type definition.
        DisplayGenericTypeInfo(d.GetType());
        DisplayGenericTypeInfo(d.GetType().GetGenericTypeDefinition());
        // Display information for an ordinary type.
        DisplayGenericTypeInfo(String.class.ToType());
    } //main
} //Test

/* This example produces the following output:

--- Display information about a constructed type, its
    generic type definition, and an ordinary type.

System.Collections.Generic.Dictionary[System.String,Test]
        Is this a generic type definition? False
        Is it a generic type? True
        List type arguments (2):
                System.String
                Test

System.Collections.Generic.Dictionary[TKey,TValue]
        Is this a generic type definition? True
        Is it a generic type? True
        List type arguments (2):
                TKey    (unassigned - parameter position 0)
                TValue  (unassigned - parameter position 1)

System.String
        Is this a generic type definition? False
        Is it a generic type? False
 */
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

Type.IsGenericTypeDefinition プロパティのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



Type.IsGenericTypeDefinition プロパティのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.

©2024 GRAS Group, Inc.RSS