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

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

適用対象

こちらもご覧ください