TypeFilter TypeFilter TypeFilter TypeFilter Delegate

Определение

Отфильтровывает классы, представленные в массиве объектов Type.Filters the classes represented in an array of Type objects.

public delegate bool TypeFilter(Type ^ m, System::Object ^ filterCriteria);
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public delegate bool TypeFilter(Type m, object filterCriteria);
type TypeFilter = delegate of Type * obj -> bool
Public Delegate Function TypeFilter(m As Type, filterCriteria As Object) As Boolean 

Параметры

m
Type Type Type Type

Объект Type, к которому применяется фильтр.The Type object to which the filter is applied.

filterCriteria
Object Object Object Object

Произвольный объект, используемый для фильтрации списка.An arbitrary object used to filter the list.

Возвращаемое значение

System.Boolean

Значение true для включения объекта Type в отфильтрованный список. В противном случае — значение false.true to include the Type in the filtered list; otherwise false.

Наследование
TypeFilterTypeFilterTypeFilterTypeFilter
Атрибуты

Примеры

В этом примере показано, как определить метод, соответствующий TypeFilter прототипу делегата, который позволяет использовать отражение для фильтрации или возврата подмножества совпадающих записей.This example shows how to define a method matching the TypeFilter delegate prototype allowing you to use reflection to filter or return a subset of matching entries.

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 Делегат используется для фильтрации списка классов.The TypeFilter delegate is used to filter a list of classes. В частности, он используется для фильтрации классов, представленных в массиве Type объектов.Specifically, you use it to filter the classes represented in an array of Type objects. Type.FindInterfaces Метод использует этот делегат для фильтрации списка возвращаемых интерфейсов.The Type.FindInterfaces method uses this delegate to filter the list of interfaces that it returns. Каждый производный класс Delegate класса MulticastDelegate и DynamicInvoke имеет конструктор и метод.Every derived class of Delegate and MulticastDelegate has a constructor and a DynamicInvoke method. См. пример C++ визуального кода, заданный в Delegateописании для.See the Visual C++ code example given in the description for Delegate.

Методы расширения

GetMethodInfo(Delegate) GetMethodInfo(Delegate) GetMethodInfo(Delegate) GetMethodInfo(Delegate)

Получает объект, представляющий метод, представленный указанным делегатом.Gets an object that represents the method represented by the specified delegate.

Применяется к

Дополнительно