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);
[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 オブジェクト (型がこのモジュール内にある場合)。それ以外の場合は null

属性

例外

classNamenullです。

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

className は長さ 0 の文字列です。

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

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

-または-

現在のアセンブリはリフレクションのみのコンテキストに読み込まれ、 className にはプリロードされていない依存アセンブリが必要です。

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

-または-

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

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

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

注釈

Note

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

型は、 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);
[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 オブジェクト (型がこのモジュール内にある場合)。それ以外の場合は null

属性

例外

classNamenullです。

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

className は長さ 0 の文字列です。

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

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

-または-

現在のアセンブリはリフレクションのみのコンテキストに読み込まれ、 className にはプリロードされていない依存アセンブリが必要です。

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

-または-

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

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

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

注釈

Note

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

型は、 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);
[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

true型が見つからない場合に例外をスローする場合。falseを返すnull

ignoreCase
Boolean

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

返品

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

属性

例外

classNamenullです。

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

className は長さ 0 の文字列です。

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

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

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

-または-

現在のアセンブリはリフレクションのみのコンテキストに読み込まれ、 className にはプリロードされていない依存アセンブリが必要です。

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

-または-

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

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

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 パラメーターは、型が見つからない場合の動作にのみ影響します。 スローされる可能性のある他の例外には影響しません。 特に、型が見つかったが読み込めない場合は、throwOnErrorfalseされた場合でも、TypeLoadExceptionをスローできます。

Note

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

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

適用対象