Module.GetType メソッド (String, Boolean)
指定した大文字小文字の区別の扱いに従ってモジュールを検索し、指定したクラスを返します。
Overloads Public Overridable Function GetType( _
ByVal className As String, _ ByVal ignoreCase As Boolean _) As Type
[C#]
public virtual Type GetType(stringclassName,boolignoreCase);
[C++]
public: virtual Type* GetType(String* className,boolignoreCase);
[JScript]
public function GetType(
className : String,ignoreCase : Boolean) : Type;
パラメータ
- className
検索対象のクラスの名前。この名前は、名前空間を含む完全限定名であることが必要です。 - ignoreCase
大文字小文字を区別しない検索を行う場合は true 。それ以外の場合は false 。
戻り値
クラスがこのモジュールに含まれている場合は、指定されたクラス名を表す Type オブジェクト。それ以外の場合は null 参照 (Visual Basic では Nothing) 。
例外
例外の種類 | 条件 |
---|---|
ArgumentNullException | className が null 参照 (Visual Basic では Nothing) です。 |
TargetInvocationException | クラス初期化子が呼び出され、例外がスローされます。 |
ArgumentException | className が無効です。1,023 文字を超えているか、長さ 0 の文字列であるなどの理由が考えられます。 |
SecurityException | 呼び出し元が必要なリフレクション アクセス許可を持たずに、パブリックではない型にリフレクションしようとしました。 |
使用例
[Visual Basic, C#, C++] 指定したモジュールのクラスの名前を表示する例を次に示します。この例では、大文字と小文字を区別するため ignoreCase パラメータに false を指定します。
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 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 '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 these classes.
Module myModule = moduleArray[0];
Type myType;
myType = myModule.GetType("ReflectionModule_Examples.MyMainClass", 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 these classes.
Module* myModule = moduleArray[0];
Type* myType;
myType = myModule->GetType(S"ReflectionModule_Examples.MyMainClass", false);
Console::WriteLine(S"Got type: {0}", myType);
}
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ
.NET Framework セキュリティ:
- ReflectionPermission (非パブリック型をリフレクション操作するために必要なアクセス許可) ReflectionPermissionFlag.TypeInformation (関連する列挙体)
参照
Module クラス | Module メンバ | System.Reflection 名前空間 | Module.GetType オーバーロードの一覧