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
。 の説明に記載されている Visual C++ コード例を参照 Delegate
してください。
拡張メソッド
GetMethodInfo(Delegate) |
指定したデリゲートによって表されるメソッドを表すオブジェクトを取得します。 |
適用対象
こちらもご覧ください
.NET