TypeFilter 대리자

정의

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

목록을 필터링하는 데 사용되는 임의 개체입니다.

반환 값

Boolean

필터링된 목록에 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 이 대리자를 사용하여 반환되는 인터페이스 목록을 필터링합니다. 파생된 모든 클래스 Delegate 에는 MulticastDelegate 생성자와 메서드가 있습니다 DynamicInvoke . 에 대한 설명에 제공된 Visual C++ 코드 예제를 Delegate참조하세요.

확장 메서드

GetMethodInfo(Delegate)

지정된 대리자가 나타내는 메서드를 나타내는 개체를 가져옵니다.

적용 대상

추가 정보