Imports System
Imports System.Xml
Imports System.Reflection
Imports Microsoft.VisualBasic
Public Class MyFindInterfacesSample
Public Shared Sub Main()
Dim myType As Type = New XmlDocument().GetType()
Dim myFilter As New TypeFilter(AddressOf MyInterfaceFilter)
Dim myInterfaceList() As String = {"System.Collections.IEnumerable","System.Collections.ICollection"}
Dim index As Integer
For index = 0 To myInterfaceList.Length - 1
Dim myInterfaces As Type() = myType.FindInterfaces(myFilter, myInterfaceList(index))
If myInterfaces.Length > 0 Then
Console.WriteLine("{0} implements the interface {1}.", myType, myInterfaceList(index))
Dim j As Integer
For j = 0 To myInterfaces.Length - 1
Console.WriteLine("Interfaces supported: {0}",myInterfaces(j).ToString())
Next j
Else
Console.WriteLine("{0} does not implement the interface {1}.",myType, myInterfaceList(index))
End If
Next index
End Sub
Public Shared Function MyInterfaceFilter(ByVal typeObj As Type, _
ByVal criteriaObj As [Object]) As Boolean
If typeObj.ToString() = criteriaObj.ToString() Then
Return True
Else
Return False
End If
End Function
End Class
|