本文整理匯總了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