다음을 통해 공유


TypeFilter 대리자

Type 개체의 배열에 나타난 클래스를 필터링합니다.

네임스페이스: System.Reflection
어셈블리: mscorlib(mscorlib.dll)

구문

‘선언
<SerializableAttribute> _
<ComVisibleAttribute(True)> _
Public Delegate Function TypeFilter ( _
    m As Type, _
    filterCriteria As Object _
) As Boolean
‘사용 방법
Dim instance As New TypeFilter(AddressOf HandlerMethod)
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
public delegate bool TypeFilter (
    Type m,
    Object filterCriteria
)
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
public delegate bool TypeFilter (
    Type^ m, 
    Object^ filterCriteria
)
/** @delegate */
/** @attribute SerializableAttribute() */ 
/** @attribute ComVisibleAttribute(true) */ 
public delegate boolean TypeFilter (
    Type m, 
    Object filterCriteria
)
JScript에서는 대리자를 사용할 수 있지만 새로 선언할 수는 없습니다.

매개 변수

  • m
    필터가 적용된 Type 개체입니다.
  • filterCriteria
    목록을 필터링할 때 사용되는 임의의 개체입니다.

반환 값

필터링된 목록의 Type을 포함하려면 true이고, 그렇지 않으면 false입니다.

설명

TypeFilter 대리자는 클래스의 목록을 필터링하는 데 사용됩니다. 특히 Type 개체의 배열에 나타난 클래스를 필터링하는 데 사용됩니다. Type.FindInterfaces 메서드는 이 대리자를 사용하여 반환되는 인터페이스 목록을 필터링합니다. DelegateMulticastDelegate의 각 파생 클래스에 생성자 및 DynamicInvoke 메서드가 있습니다. Delegate에 대한 설명에 제공된 Managed Extensions for C++ 코드 예제를 참조하십시오.

예제

이 예제에서는 리플렉션을 사용하여 일치하는 항목의 하위 집합을 반환하거나 필터링할 수 있도록 TypeFilter 대리자 프로토타입과 일치하는 메서드를 정의하는 방법을 보여 줍니다.

Imports system
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 four interfaces; two are defined in this assembly and two are defined in another assembly.
Public Class MyRetailer
    Implements IBookRetailer, IMusicRetailer, IComparable, ICloneable

    ' For demonstration purposes, this method returns nothing; it just allows the code to compile.
    Public Function Clone() As Object Implements System.ICloneable.Clone
        Return Nothing
    End Function

    ' For demonstration purposes, this method returns nothing; it just allows the code to compile.
    Public Function CompareTo(ByVal obj As Object) As Integer Implements System.IComparable.CompareTo
        Return Nothing
    End Function

    ' For demonstration purposes, this method returns nothing; it just allows the code to compile.
    Public Sub ApplyDiscout() Implements IBookRetailer.ApplyDiscount
    End Sub

    ' For demonstration purposes, this method returns nothing; it just allows the code to compile.
    Public Sub Purchase() Implements IBookRetailer.Purchase
    End Sub

    ' For demonstration purposes, this method returns nothing; it just allows the code to compile.
    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 interfaces() As Type = _
            GetType(MyRetailer).FindInterfaces(AddressOf TypeFilter, Assembly.GetExecutingAssembly().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):")
        Dim t As Type
        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 interface defined.
    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

' Output will vary based on the contents of the C drive.
'
' This code produces the following output.
' MyRetailer implements the following interfaces (defined in this assembly):
'   IBookRetailer
'   IMusicRetailer

플랫폼

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.

버전 정보

.NET Framework

2.0, 1.1, 1.0에서 지원

참고 항목

참조

System.Reflection 네임스페이스
FindInterfaces
Object
Delegate
MulticastDelegate