Module.FindTypes(TypeFilter, Object) Metódus

Definíció

Az adott szűrő- és szűrőfeltételek által elfogadott osztálytömböt adja vissza.

public:
 virtual cli::array <Type ^> ^ FindTypes(System::Reflection::TypeFilter ^ filter, System::Object ^ filterCriteria);
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Types might be removed")]
public virtual Type[] FindTypes(System.Reflection.TypeFilter? filter, object? filterCriteria);
public virtual Type[] FindTypes(System.Reflection.TypeFilter filter, object filterCriteria);
public virtual Type[] FindTypes(System.Reflection.TypeFilter? filter, object? filterCriteria);
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Types might be removed")>]
abstract member FindTypes : System.Reflection.TypeFilter * obj -> Type[]
override this.FindTypes : System.Reflection.TypeFilter * obj -> Type[]
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()

Paraméterek

filter
TypeFilter

Az osztályok szűréséhez használt meghatalmazott.

filterCriteria
Object

Az osztályok szűrésére használt objektum.

Válaszok

Type[]

Olyan típusú Type tömb, amely a szűrő által elfogadott osztályokat tartalmazza.

Attribútumok

Kivételek

Egy modul egy vagy több osztálya nem tölthető be.

Példák

Az alábbi példa a metódust FindTypes mutatja be.

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

Megjegyzések

ReflectionTypeLoadException egy speciális osztálybetöltési kivétel. A ReflectionTypeLoadException.Types tulajdonság tartalmazza a modulban definiált és betöltött osztályok tömbét. Ez a tömb tartalmazhat null értékeket. A ReflectionTypeLoadException.LoaderExceptions tulajdonság a kivételeket tartalmazó tömb, amely az osztálybetöltő által kidobott kivételeket jelöli. Az osztálytömbben lévő lyukak a kivételekkel egybeesnek.

A modul minden osztályához meghívjuk az általa filter megadott delegáltat, amely az Type osztályt és az adott filterCriteriaosztályt képviselő objektum mentén halad végig. Ha filter egy adott osztályt ad vissza, az adott osztály szerepelni fog a visszaadott tömbben. Ha filter visszaadja, nulla rendszer az összes osztályt visszaadja, és filterCriteria figyelmen kívül hagyja.

FindTypes nem használható paraméteres típusok, például tömbök keresésére.

A következőre érvényes:

Lásd még