Module.FindTypes(TypeFilter, Object) メソッド

定義

指定したフィルターとフィルター条件で受け入れられたクラスの配列を返します。

public:
 virtual cli::array <Type ^> ^ FindTypes(System::Reflection::TypeFilter ^ filter, System::Object ^ filterCriteria);
public virtual Type[] FindTypes (System.Reflection.TypeFilter? filter, object? filterCriteria);
public virtual Type[] FindTypes (System.Reflection.TypeFilter filter, object filterCriteria);
abstract member FindTypes : System.Reflection.TypeFilter * obj -> Type[]
override this.FindTypes : System.Reflection.TypeFilter * obj -> Type[]
Public Overridable Function FindTypes (filter As TypeFilter, filterCriteria As Object) As Type()

パラメーター

filter
TypeFilter

クラスのフィルター処理に使用するデリゲート。

filterCriteria
Object

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

戻り値

Type[]

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

例外

モジュールの 1 つまたは複数のクラスを読み込むことができませんでした。

FindTypesメソッドの例を次に示します。

using namespace System;
using namespace System::Reflection;
using namespace System::Collections;
public ref class MySecondClass{};


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

int main()
{
   array<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 ];
   array<Type^>^tArray;
   tArray = myModule->FindTypes( Module::FilterTypeName, "My*" );
   IEnumerator^ myEnum = tArray->GetEnumerator();
   while ( myEnum->MoveNext() )
   {
      Type^ t = safe_cast<Type^>(myEnum->Current);
      Console::WriteLine( "Found a module beginning with My*: {0}.", t->Name );
   }
}
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[] 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
    {
    }
}
Imports System.Reflection

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 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
    End Class

    Class MySecondClass
    End Class

    ' This class does not fit the filter criteria My*.
    Class YourClass
    End Class
End Namespace 'ReflectionModule_Examples

注釈

ReflectionTypeLoadException は特別なクラス読み込み例外です。 プロパティには ReflectionTypeLoadException.Types 、モジュールで定義され、読み込まれたクラスの配列が含まれています。 この配列には、いくつかの null 値を含めることができます。 プロパティは ReflectionTypeLoadException.LoaderExceptions 、クラス ローダーによってスローされた例外を表す例外の配列です。 クラス配列の穴は例外と一緒に並びます。

によって指定されたfilterデリゲートは、モジュール内の各クラスに対して呼び出され、クラスを表す オブジェクトと指定filterCriteriaされた を渡Typeします。 が特定のクラスを返す場合 filter 、そのクラスは返される配列に含まれます。 が を返すnull場合filter、すべてのクラスが返され、filterCriteria無視されます。

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

適用対象

こちらもご覧ください