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 형식의 배열입니다.

예외

모듈에 있는 하나 이상의 클래스를 로드할 수 없는 경우

예제

다음 예제는 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 클래스 로더에 의해 throw된 예외를 나타내는 예외의 배열입니다. 클래스 배열의 구멍은 예외와 함께 정렬됩니다.

에 지정된 filter 대리자는 지정된 와 함께 클래스를 나타내는 개체를 전달하여 모듈의 Type 각 클래스에 filterCriteria대해 호출됩니다. 특정 클래스를 반환하는 경우 filter 해당 클래스는 반환된 배열에 포함됩니다. 가 를 반환null하면 filter 모든 클래스가 반환되고 filterCriteria 무시됩니다.

FindTypes 는 배열과 같은 매개 변수가 있는 형식을 조회하는 데 사용할 수 없습니다.

적용 대상

추가 정보