TypeFilter 委托
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
筛选 Type 对象数组中表示的类。
public delegate bool TypeFilter(Type ^ m, System::Object ^ filterCriteria);
public delegate bool TypeFilter(Type m, object? filterCriteria);
public delegate bool TypeFilter(Type m, object filterCriteria);
[System.Serializable]
public delegate bool TypeFilter(Type m, object filterCriteria);
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public delegate bool TypeFilter(Type m, object filterCriteria);
type TypeFilter = delegate of Type * obj -> bool
[<System.Serializable>]
type TypeFilter = delegate of Type * obj -> bool
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type TypeFilter = delegate of Type * obj -> bool
Public Delegate Function TypeFilter(m As Type, filterCriteria As Object) As Boolean
参数
- m
- Type
对其应用筛选器的 Type
对象。
- filterCriteria
- Object
用于筛选列表的任意对象。
返回值
若要在筛选后的列表中包括 Type,则为 true
;否则为 false
。
- 属性
示例
此示例演示如何定义与委托原型匹配的方法, TypeFilter 以便使用反射来筛选或返回匹配条目的子集。
Imports System.Reflection
' This interface is defined in this assembly.
Public Interface IBookRetailer
Sub Purchase()
Sub ApplyDiscount()
End Interface
' This interface is also defined in this assembly.
Public Interface IMusicRetailer
Sub Purchase()
End Interface
' This class implements three interfaces;
' Two are defined in this assembly.
' One is defined in another assembly.
Public Class MyRetailer
Implements IBookRetailer, IMusicRetailer, IComparable
' For demonstration purposes, this method returns nothing.
Public Function CompareTo(ByVal obj As Object) As Integer Implements System.IComparable.CompareTo
Return Nothing
End Function
' For demonstration purposes only, this method does nothing.
Public Sub ApplyDiscount() Implements IBookRetailer.ApplyDiscount
End Sub
' For demonstration purposes only, this method does nothing.
Public Sub Purchase() Implements IBookRetailer.Purchase
End Sub
' For demonstration purposes only, this method does nothing.
Public Sub Purchase1() Implements IMusicRetailer.Purchase
End Sub
End Class
Module Module1
Sub Main()
' Find the interfaces defined by the MyRetailer class. Each interface found is passed to
' the TypeFilter method which checks if the interface is defined in the executing assembly.
Dim retailerType As Type = GetType(MyRetailer)
Dim interfaces() As Type = _
retailerType.FindInterfaces(AddressOf TypeFilter, retailerType.Assembly.GetName().ToString())
' Show the interfaces that are defined in this assembly that are also implemented by MyRetailer.
Console.WriteLine("MyRetailer implements the following interfaces (defined in this assembly):")
For Each t In interfaces
Console.WriteLine(" {0}", t.Name)
Next
End Sub
' This method is called by the FindInterfaces method.
' This method is called once per defined interface.
Function TypeFilter(ByVal t As Type, ByVal filterCriteria As Object) As Boolean
' Return true if interface is defined in the same
' assembly identified by the filterCriteria object.
Return t.Assembly.GetName().ToString() = CType(filterCriteria, String)
End Function
End Module
' The example displays the following output:
' MyRetailer implements the following interfaces (defined in this assembly):
' IBookRetailer
' IMusicRetailer
注解
委托 TypeFilter
用于筛选类列表。 具体而言,可以使用它筛选对象数组中表示的 Type 类。 方法 Type.FindInterfaces 使用此委托来筛选它返回的接口列表。 和 MulticastDelegate 的每个派生类Delegate都有一个构造函数和一个DynamicInvoke
方法。 请参阅 的说明 Delegate
中提供的 Visual C++ 代码示例。
扩展方法
GetMethodInfo(Delegate) |
获取指示指定委托表示的方法的对象。 |