Module.FindTypes 方法

返回给定的筛选器和筛选条件接受的类数组。

**命名空间:**System.Reflection
**程序集:**mscorlib(在 mscorlib.dll 中)

语法

声明
Public Overridable Function FindTypes ( _
    filter As TypeFilter, _
    filterCriteria As Object _
) As Type()
用法
Dim instance As Module
Dim filter As TypeFilter
Dim filterCriteria As Object
Dim returnValue As Type()

returnValue = instance.FindTypes(filter, filterCriteria)
public virtual Type[] FindTypes (
    TypeFilter filter,
    Object filterCriteria
)
public:
virtual array<Type^>^ FindTypes (
    TypeFilter^ filter, 
    Object^ filterCriteria
)
public Type[] FindTypes (
    TypeFilter filter, 
    Object filterCriteria
)
public function FindTypes (
    filter : TypeFilter, 
    filterCriteria : Object
) : Type[]

参数

  • filter
    用于筛选类的委托。
  • filterCriteria
    用于筛选类的对象。

返回值

包含筛选器接受的类的 Type 类型数组。

异常

异常类型 条件

ReflectionTypeLoadException

未能加载模块中的一个或多个类。

备注

ReflectionTypeLoadException 是特殊的类加载异常。ReflectionTypeLoadException.Types 属性包含类数组,这些类在模块中定义并被加载。此数组可能包含一些空值。ReflectionTypeLoadException.LoaderExceptions 属性是一个异常数组,这些异常表示由类加载程序引发的异常。类数组中的空缺也属于异常。

为模块中的每个类调用 filter 给定的委托,并传递表示此类的 Type 对象和给定的 filterCriteria。如果 filter 返回一个特定类,则该类将包含在返回的数组中。如果 filter 返回 空引用(在 Visual Basic 中为 Nothing),则返回所有类并忽略 filterCriteria。

FindTypes 无法用于查找数组这样的参数化类型。

示例

下面的示例说明 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
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
    {
    }
}
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 );
   }
}
package ReflectionModule_Examples;
 
import System.*;
import System.Reflection.*;

class MyMainClass
{

    public static void main(String[] args)
    {
        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 = (Module)moduleArray.get_Item(0);
        Type tArray[];
        tArray = myModule.FindTypes(Module.FilterTypeName, "My*");
        for (int iCtr = 0; iCtr < tArray.length; iCtr++) {
            Type t = tArray[iCtr];
            Console.WriteLine("Found a module beginning with My*: {0}.",
                t.get_Name());
        }
    } //main
} //MyMainClass

class MySecondClass
{
} //MySecondClass

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

平台

Windows 98、Windows 2000 SP4、Windows Millennium Edition、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

请参见

参考

Module 类
Module 成员
System.Reflection 命名空间
FilterTypeName
FilterTypeNameIgnoreCase
ReflectionTypeLoadException