本文整理汇总了VB.NET中System.Type.FindInterfaces方法的典型用法代码示例。如果您正苦于以下问题:VB.NET Type.FindInterfaces方法的具体用法?VB.NET Type.FindInterfaces怎么用?VB.NET Type.FindInterfaces使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Type
的用法示例。
在下文中一共展示了Type.FindInterfaces方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: MyFindInterfacesSample
' 导入命名空间
Imports System.Xml
Imports System.Reflection
Public Class MyFindInterfacesSample
Public Shared Sub Main()
Try
Dim myXMLDoc As New XmlDocument()
myXMLDoc.LoadXml("<book genre='novel' ISBN='1-861001-57-5'>" _
& "<title>Pride And Prejudice</title>" & "</book>")
Dim myType As Type = myXMLDoc.GetType()
' Specify the TypeFilter delegate that compares the
' interfaces against filter criteria.
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(ControlChars.Cr & _
"{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(ControlChars.Cr & _
"{0} does not implement the interface {1}.", _
myType, myInterfaceList(index))
End If
Next index
Catch e As ArgumentNullException
Console.WriteLine("ArgumentNullException: " & e.Message)
Catch e As TargetInvocationException
Console.WriteLine("TargetInvocationException: " & e.Message)
Catch e As Exception
Console.WriteLine("Exception: " & e.Message)
End Try
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 'MyInterfaceFilter
End Class