Module.GetType メソッド

定義

指定した型を返します。

オーバーロード

GetType(String)

大文字小文字を区別する検索を実行して、指定された型を返します。

GetType(String, Boolean)

指定された大文字と小文字の区別でモジュールを検索し、指定された型を返します。

GetType(String, Boolean, Boolean)

大文字小文字を区別したモジュール検索を実行するかどうか、および型が見つからない場合に例外をスローするかどうかを指定して、指定された型を返します。

GetType(String)

大文字小文字を区別する検索を実行して、指定された型を返します。

public:
 virtual Type ^ GetType(System::String ^ className);
public virtual Type? GetType (string className);
public virtual Type GetType (string className);
[System.Runtime.InteropServices.ComVisible(true)]
public virtual Type GetType (string className);
override this.GetType : string -> Type
[<System.Runtime.InteropServices.ComVisible(true)>]
override this.GetType : string -> Type
Public Overridable Function GetType (className As String) As Type

パラメーター

className
String

検索対象の型の名前。 この名前は、名前空間を含む完全修飾名であることが必要です。

戻り値

Type

型がこのモジュールに含まれている場合は、指定された型を表す Type オブジェクト。それ以外の場合は null

属性

例外

classNamenullです。

クラスの初期化子が呼び出され、例外がスローされます。

className は長さゼロの文字列です。

className には見つからなかった依存アセンブリが必要です。

className には、見つかったものの読み込めなかった依存アセンブリが必要です。

  • または - 現在のアセンブリはリフレクションのみのコンテキストに読み込まれましたが、className には事前に読み込まれていない依存アセンブリが必要です。

className には依存アセンブリが必要ですが、ファイルは有効なアセンブリではありません。

  • または - className には、現在読み込まれているバージョンより新しいバージョンのランタイム用にコンパイルされた依存アセンブリが必要です。

次の例では、指定したモジュール内の型の名前を表示します。

using namespace System;
using namespace System::Reflection;

namespace ReflectionModule_Examples
{
   public ref class MyMainClass{};

}

int main()
{
   array<Module^>^moduleArray;
   moduleArray = ReflectionModule_Examples::MyMainClass::typeid->Assembly->GetModules( false );
   
   //In a simple project with only one module, the module at index
   // 0 will be the module containing these classes.
   Module^ myModule = moduleArray[ 0 ];
   Type^ myType;
   myType = myModule->GetType( "ReflectionModule_Examples.MyMainClass" );
   Console::WriteLine( "Got type: {0}", myType );
}
using System;
using System.Reflection;

namespace ReflectionModule_Examples
{
    class MyMainClass
    {
        static void Main()
        {
            Module[] moduleArray;
            
            moduleArray = typeof(MyMainClass).Assembly.GetModules(false);
            
            //In a simple project with only one module, the module at index
            // 0 will be the module containing these classes.
            Module myModule = moduleArray[0];

            Type myType;

            myType = myModule.GetType("ReflectionModule_Examples.MyMainClass");
            Console.WriteLine("Got type: {0}", myType.ToString());
        }
    }
}
Imports System.Reflection

'This code assumes that the root namespace is set to empty("").
Namespace ReflectionModule_Examples
    Class MyMainClass
        Shared Sub Main()
            Dim moduleArray() As [Module]

            moduleArray = GetType(MyMainClass).Assembly.GetModules(False)

            'In a simple project with only one module, the module at index
            ' 0 will be the module containing these classes.
            Dim myModule As [Module] = moduleArray(0)

            Dim myType As Type

            myType = myModule.GetType("ReflectionModule_Examples.MyMainClass")
            Console.WriteLine("Got type: {0}", myType.ToString())
        End Sub
    End Class
End Namespace 'ReflectionModule_Examples

注釈

注意

型が別のアセンブリに転送された場合でも、このメソッドによって返されます。 型転送の詳細については、「 共通言語ランタイムでの型の転送」を参照してください。

型は、次を使用して Module.GetType特定のモジュールから取得できます。 マニフェストを含むモジュールを呼び出 Module.GetType すと、アセンブリ全体は検索されません。 アセンブリから型を取得するには、アセンブリがどのモジュールにあるかに関係なく、呼び出す Assembly.GetType必要があります。

適用対象

GetType(String, Boolean)

指定された大文字と小文字の区別でモジュールを検索し、指定された型を返します。

public:
 virtual Type ^ GetType(System::String ^ className, bool ignoreCase);
public virtual Type? GetType (string className, bool ignoreCase);
public virtual Type GetType (string className, bool ignoreCase);
[System.Runtime.InteropServices.ComVisible(true)]
public virtual Type GetType (string className, bool ignoreCase);
override this.GetType : string * bool -> Type
[<System.Runtime.InteropServices.ComVisible(true)>]
override this.GetType : string * bool -> Type
Public Overridable Function GetType (className As String, ignoreCase As Boolean) As Type

パラメーター

className
String

検索対象の型の名前。 この名前は、名前空間を含む完全修飾名であることが必要です。

ignoreCase
Boolean

大文字小文字を区別しない検索を行う場合は true。それ以外の場合は false

戻り値

Type

型がこのモジュールに含まれている場合は、指定された型を表す Type オブジェクト。それ以外の場合は null

属性

例外

classNamenullです。

クラスの初期化子が呼び出され、例外がスローされます。

className は長さゼロの文字列です。

className には見つからなかった依存アセンブリが必要です。

className には、見つかったものの読み込めなかった依存アセンブリが必要です。

  • または - 現在のアセンブリはリフレクションのみのコンテキストに読み込まれましたが、className には事前に読み込まれていない依存アセンブリが必要です。

className には依存アセンブリが必要ですが、ファイルは有効なアセンブリではありません。

  • または - className には、現在読み込まれているバージョンより新しいバージョンのランタイム用にコンパイルされた依存アセンブリが必要です。

次の例では、指定したモジュール内の型の名前を表示し、その大文字と小文字が無視されないようにパラメーターをignoreCase指定falseします。

using namespace System;
using namespace System::Reflection;

namespace ReflectionModule_Examples
{
   public ref class MyMainClass{};

}

int main()
{
   array<Module^>^moduleArray;
   moduleArray = ReflectionModule_Examples::MyMainClass::typeid->Assembly->GetModules( false );
   
   //In a simple project with only one module, the module at index
   // 0 will be the module containing these classes.
   Module^ myModule = moduleArray[ 0 ];
   Type^ myType;
   myType = myModule->GetType( "ReflectionModule_Examples.MyMainClass", false );
   Console::WriteLine( "Got type: {0}", myType );
}
using System;
using System.Reflection;

namespace ReflectionModule_Examples
{
    class MyMainClass
    {
        static void Main()
        {
            Module[] moduleArray;
            
            moduleArray = typeof(MyMainClass).Assembly.GetModules(false);
            
            //In a simple project with only one module, the module at index
            // 0 will be the module containing these classes.
            Module myModule = moduleArray[0];

            Type myType;
            myType = myModule.GetType("ReflectionModule_Examples.MyMainClass", false);
            Console.WriteLine("Got type: {0}", myType.ToString());
        }
    }
}
Imports System.Reflection

'This code assumes that the root namespace is set to empty("").
Namespace ReflectionModule_Examples
    Class MyMainClass
        Shared Sub Main()
            Dim moduleArray() As [Module]

            moduleArray = GetType(MyMainClass).Assembly.GetModules(False)

            'In a simple project with only one module, the module at index
            ' 0 will be the module containing these classes.
            Dim myModule As [Module] = moduleArray(0)

            Dim myType As Type
            myType = myModule.GetType("ReflectionModule_Examples.MyMainClass", False)
            Console.WriteLine("Got type: {0}", myType.ToString())
        End Sub
    End Class
End Namespace 'ReflectionModule_Examples

注釈

注意

型が別のアセンブリに転送された場合でも、このメソッドによって返されます。 型転送の詳細については、「 共通言語ランタイムでの型の転送」を参照してください。

型は、次を使用して Module.GetType特定のモジュールから取得できます。 マニフェストを含むモジュールを呼び出 Module.GetType すと、アセンブリ全体は検索されません。 アセンブリから型を取得するには、アセンブリがどのモジュールにあるかに関係なく、呼び出す Assembly.GetType必要があります。

適用対象

GetType(String, Boolean, Boolean)

大文字小文字を区別したモジュール検索を実行するかどうか、および型が見つからない場合に例外をスローするかどうかを指定して、指定された型を返します。

public:
 virtual Type ^ GetType(System::String ^ className, bool throwOnError, bool ignoreCase);
public virtual Type GetType (string className, bool throwOnError, bool ignoreCase);
public virtual Type? GetType (string className, bool throwOnError, bool ignoreCase);
[System.Runtime.InteropServices.ComVisible(true)]
public virtual Type GetType (string className, bool throwOnError, bool ignoreCase);
override this.GetType : string * bool * bool -> Type
[<System.Runtime.InteropServices.ComVisible(true)>]
override this.GetType : string * bool * bool -> Type
Public Overridable Function GetType (className As String, throwOnError As Boolean, ignoreCase As Boolean) As Type

パラメーター

className
String

検索対象の型の名前。 この名前は、名前空間を含む完全修飾名であることが必要です。

throwOnError
Boolean

型が見つからなかったときに例外をスローする場合は truefalse を返す場合は null

ignoreCase
Boolean

大文字小文字を区別しない検索を行う場合は true。それ以外の場合は false

戻り値

Type

型がこのモジュールで宣言されている場合は、指定された型を表す Type オブジェクト。それ以外の場合は null

属性

例外

classNamenullです。

クラスの初期化子が呼び出され、例外がスローされます。

className は長さゼロの文字列です。

throwOnErrortrueであり、型が見つかりません。

className には見つからなかった依存アセンブリが必要です。

className には、見つかったものの読み込めなかった依存アセンブリが必要です。

  • または - 現在のアセンブリはリフレクションのみのコンテキストに読み込まれましたが、className には事前に読み込まれていない依存アセンブリが必要です。

className には依存アセンブリが必要ですが、ファイルは有効なアセンブリではありません。

  • または - className には、現在読み込まれているバージョンより新しいバージョンのランタイム用にコンパイルされた依存アセンブリが必要です。

次の例では、指定したモジュール内の型の名前を表示します。 パラメーターとignoreCaseパラメーターはthrowOnError次のようにfalse指定されます。

using namespace System;
using namespace System::Reflection;

namespace ReflectionModule_Examples
{
   public ref class MyMainClass{};

}

int main()
{
   array<Module^>^moduleArray;
   moduleArray = ReflectionModule_Examples::MyMainClass::typeid->Assembly->GetModules( false );
   
   //In a simple project with only one module, the module at index
   // 0 will be the module containing this class.
   Module^ myModule = moduleArray[ 0 ];
   Type^ myType;
   myType = myModule->GetType( "ReflectionModule_Examples.MyMainClass", false, false );
   Console::WriteLine( "Got type: {0}", myType );
}
using System;
using System.Reflection;

namespace ReflectionModule_Examples
{
    class MyMainClass
    {
        static void Main()
        {
            Module[] moduleArray;
            
            moduleArray = typeof(MyMainClass).Assembly.GetModules(false);
            
            //In a simple project with only one module, the module at index
            // 0 will be the module containing this class.
            Module myModule = moduleArray[0];

            Type myType;
            myType = myModule.GetType("ReflectionModule_Examples.MyMainClass", false, false);
            Console.WriteLine("Got type: {0}", myType.ToString());
        }
    }
}
Imports System.Reflection

'This code assumes that the root namespace is set to empty("").
Namespace ReflectionModule_Examples
    Class MyMainClass
        Shared Sub Main()
            Dim moduleArray() As [Module]

            moduleArray = GetType(MyMainClass).Assembly.GetModules(False)

            'In a simple project with only one module, the module at index
            ' 0 will be the module containing this class.
            Dim myModule As [Module] = moduleArray(0)

            Dim myType As Type
            myType = myModule.GetType("ReflectionModule_Examples.MyMainClass", False, False)
            Console.WriteLine("Got type: {0}", myType.ToString())
        End Sub
    End Class
End Namespace 'ReflectionModule_Examples

注釈

このパラメーターは throwOnError 、型が見つからない場合の動作にのみ影響します。 スローされる可能性がある他の例外には影響しません。 特に、型が見つかったが読み込めない場合はfalseTypeLoadException次の場合throwOnErrorでもスローできます。

注意

型が別のアセンブリに転送された場合でも、このメソッドによって返されます。 型転送の詳細については、「 共通言語ランタイムでの型の転送」を参照してください。

型は、次を使用して Module.GetType特定のモジュールから取得できます。 マニフェストを含むモジュールを呼び出 Module.GetType すと、アセンブリ全体は検索されません。 アセンブリから型を取得するには、アセンブリがどのモジュールにあるかに関係なく、呼び出す Assembly.GetType必要があります。

適用対象