Share via


Module.FindTypes メソッド

指定したフィルタとフィルタ基準によって受け入れられたクラスの配列を返します。

Public Overridable Function FindTypes( _
   ByVal filter As TypeFilter, _   ByVal filterCriteria As Object _) As Type()
[C#]
public virtual Type[] FindTypes(TypeFilterfilter,objectfilterCriteria);
[C++]
public: virtual Type* FindTypes(TypeFilter* filter,Object* filterCriteria) [];
[JScript]
public function FindTypes(
   filter : TypeFilter,filterCriteria : Object) : Type[];

パラメータ

  • filter
    クラスをフィルタ処理するために使用するデリゲート。
  • filterCriteria
    クラスをフィルタ処理するために使用するオブジェクト。

戻り値

フィルタが受け入れたクラスを格納している Type 型の配列。

例外

例外の種類 条件
ReflectionTypeLoadException モジュール内の 1 つ以上のクラスを読み込むことができません。

解説

ReflectionTypeLoadException は特殊なクラス読み込み例外です。 ReflectionTypeLoadException.Types プロパティは、モジュールで定義され、読み込まれたクラスの配列を格納します。この配列には null 値が含まれる場合があります。 ReflectionTypeLoadException.LoaderExceptions プロパティは、クラス ローダーがスローした例外を表す例外の配列です。クラスの配列のすきまは、この例外に合わせて並べられます。

モジュールのクラスごとに、 filter で指定されたデリゲートが、そのクラスを表す Type オブジェクトと指定した filterCriteria を渡されて呼び出されます。filter が特定のクラスを返した場合は、返される配列にそのクラスが格納されます。filter が null 参照 (Visual Basic では Nothing) を返した場合、すべてのクラスが返され、 filterCriteria は無視されます。

FindTypes を使用して、配列などパラメータ化された型を検索することはできません。

使用例

[Visual Basic, C#, C++] FindTypes メソッドの例を次に示します。

 
Imports System
Imports System.Reflection

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 tArray() As Type

            tArray = myModule.FindTypes([Module].FilterTypeName, "My*")

            Dim t As Type
            For Each t In tArray
                Console.WriteLine("Found a module beginning with My*: {0}", t.Name)
            Next t
        End Sub 'Main
    End Class 'MyMainClass

    Class MySecondClass
    End Class 'MySecondClass

    ' This class does not fit the filter criteria My*.
    Class YourClass
    End Class 'YourClass
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[] tArray;

            tArray = myModule.FindTypes(Module.FilterTypeName, "My*");
            
            foreach(Type t in tArray)
            {
                Console.WriteLine("Found a module beginning with My*: {0}.", t.Name);
            }
        }
    }

    class MySecondClass
    {
    }

    // This class does not fit the filter criteria My*.
    class YourClass
    {
    }
}

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

using namespace System;
using namespace System::Reflection;
using namespace System::Collections;

public __gc class MySecondClass
{
};

// This class does not fit the filter criterion My*.
public __gc class YourClass
{
};

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* tArray[];

   tArray = myModule->FindTypes(Module::FilterTypeName, S"My*");
   IEnumerator* myEnum = tArray->GetEnumerator();
   while (myEnum->MoveNext()) {
      Type* t = __try_cast<Type*>(myEnum->Current);
      Console::WriteLine(S"Found a module beginning with My*: {0}.", t->Name);
   }
}

[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 ファミリ

参照

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