Return Value

The TypeFilter delegate is used to filter a list of classes. Specifically, you use it to filter the classes represented in an array of Type objects. The Type.FindInterfaces method uses this delegate to filter the list of interfaces that it returns. Every derived class of Delegate and MulticastDelegate has a constructor and a DynamicInvoke method. See the Visual C++ code example given in the description for Delegate.

Imports system
Imports system.Reflection
' This interface is defined in this assembly.PublicInterface IBookRetailer
Sub Purchase()
Sub ApplyDiscount()
EndInterface' This interface is also defined in this assembly.PublicInterface IMusicRetailer
Sub Purchase()
EndInterface' This class implements four interfaces; two are defined in this assembly and two are defined in another assembly.PublicClass MyRetailer
Implements IBookRetailer, IMusicRetailer, IComparable, ICloneable
' For demonstration purposes, this method returns nothing; it just allows the code to compile.PublicFunction Clone() AsObjectImplements System.ICloneable.Clone
ReturnNothingEndFunction' For demonstration purposes, this method returns nothing; it just allows the code to compile.PublicFunction CompareTo(ByVal obj AsObject) AsIntegerImplements System.IComparable.CompareTo
ReturnNothingEndFunction' For demonstration purposes, this method returns nothing; it just allows the code to compile.PublicSub ApplyDiscout() Implements IBookRetailer.ApplyDiscount
EndSub' For demonstration purposes, this method returns nothing; it just allows the code to compile.PublicSub Purchase() Implements IBookRetailer.Purchase
EndSub' For demonstration purposes, this method returns nothing; it just allows the code to compile.PublicSub Purchase1() Implements IMusicRetailer.Purchase
EndSubEndClassModule 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
ForEach t In interfaces
Console.WriteLine(" {0}", t.Name)
NextEndSub' This method is called by the FindInterfaces method. ' This method is called once per interface defined.Function TypeFilter(ByVal t As Type, ByVal filterCriteria AsObject) AsBoolean' Return true if interface is defined in the same ' assembly identified by the filterCriteria object.Return t.Assembly.GetName().ToString() = CType(filterCriteria, String)
EndFunctionEndModule' 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