Share via


Module.GetType メソッド

指定したクラスを返します。

オーバーロードの一覧

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

.NET Compact Framework でもサポート。

[Visual Basic] Overloads Public Overridable Function GetType(String) As Type

[C#] public virtual Type GetType(string);

[C++] public: virtual Type* GetType(String*);

[JScript] public function GetType(String) : Type;

指定した大文字小文字の区別の扱いに従ってモジュールを検索し、指定したクラスを返します。

[Visual Basic] Overloads Public Overridable Function GetType(String, Boolean) As Type

[C#] public virtual Type GetType(string, bool);

[C++] public: virtual Type* GetType(String*, bool);

[JScript] public function GetType(String, Boolean) : Type;

指定した大文字小文字の区別によってモジュールを検索し、 Type の読み込み中にエラーが発生した場合に例外をスローするかどうかを指定して、指定したクラスを返します。

[Visual Basic] Overloads Public Overridable Function GetType(String, Boolean, Boolean) As Type

[C#] public virtual Type GetType(string, bool, bool);

[C++] public: virtual Type* GetType(String*, bool, bool);

[JScript] public function GetType(String, Boolean, Boolean) : Type;

Object から継承されます。

.NET Compact Framework でもサポート。

[Visual Basic] Overloads Public Function GetType() As Type

[C#] public Type GetType();

[C++] public: Type* GetType();

[JScript] public function GetType() : Type;

使用例

[Visual Basic, C#, C++] 指定したモジュールのクラスの名前を表示する例を次に示します。 throwOnError パラメータと ignoreCase パラメータは false に指定できます。

[Visual Basic, C#, C++] メモ   ここでは、GetType のオーバーロード形式のうちの 1 つだけについて、使用例を示します。その他の例については、各オーバーロード形式のトピックを参照してください。

 
Imports System
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 = [Assembly].GetExecutingAssembly().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 'Main
    End Class 'MyMainClass
End Namespace 'ReflectionModule_Examples

[C#] 
using System;
using System.Reflection;

namespace ReflectionModule_Examples
{
    class MyMainClass
    {
        static void Main()
        {
            Module[] moduleArray;
            
            moduleArray = Assembly.GetExecutingAssembly().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());
        }
    }
}

[C++] 
#using <mscorlib.dll>

using namespace System;
using namespace System::Reflection;

namespace ReflectionModule_Examples
{
   public __gc class MyMainClass
   {
   };
}

int main()
{
   Module* moduleArray[];

   moduleArray = Assembly::GetExecutingAssembly()->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(S"ReflectionModule_Examples.MyMainClass", false, false);
   Console::WriteLine(S"Got type: {0}", myType);
}

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

参照

Module クラス | Module メンバ | System.Reflection 名前空間