Module.FindTypes(TypeFilter, Object) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
傳回指定篩選器和篩選準則所接受的類別陣列。
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 的陣列,其中包含篩選器所接受的類別。
例外狀況
無法載入模組中的一或多個類別。
範例
下列範例示範 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 回特定類別,該類別將會包含在傳回的陣列中。 如果傳 filter 回 null,則會傳回所有類別,並 filterCriteria 予以忽略。
FindTypes 無法用來查閱參數化型別,例如陣列。