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) |
지정된 대리자가 나타내는 메서드를 나타내는 개체를 가져옵니다. |
적용 대상
추가 정보
GitHub에서 Microsoft와 공동 작업
이 콘텐츠의 원본은 GitHub에서 찾을 수 있으며, 여기서 문제와 끌어오기 요청을 만들고 검토할 수도 있습니다. 자세한 내용은 참여자 가이드를 참조하세요.
.NET