當前位置: 首頁>>代碼示例>>VB.NET>>正文


VB.NET MethodInfo.GetBaseDefinition方法代碼示例

本文整理匯總了VB.NET中System.Reflection.MethodInfo.GetBaseDefinition方法的典型用法代碼示例。如果您正苦於以下問題:VB.NET MethodInfo.GetBaseDefinition方法的具體用法?VB.NET MethodInfo.GetBaseDefinition怎麽用?VB.NET MethodInfo.GetBaseDefinition使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。


在下文中一共展示了MethodInfo.GetBaseDefinition方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。

示例1: BaseClass

' 導入命名空間
Imports System.Reflection

Interface Interf
   Function InterfaceImpl(n As Integer) As String
End Interface

Public Class BaseClass
   Public Overrides Function ToString() As String
      Return "Base"
   End Function

   Public Overridable Sub Method1()
      Console.WriteLine("Method1")
   End Sub

   Public Overridable Sub Method2()
      Console.WriteLine("Method2")
   End Sub

   Public Overridable Sub Method3()
      Console.WriteLine("Method3")
   End Sub
End Class

Public Class DerivedClass : Inherits BaseClass : Implements Interf
   Public Function InterfaceImpl(n As Integer) As String _
                   Implements Interf.InterfaceImpl
      Return n.ToString("N")
   End Function

   Public Overrides Sub Method2()
      Console.WriteLine("Derived.Method2")
   End Sub

   Public Shadows Sub Method3()
      Console.WriteLine("Derived.Method3")
   End Sub
End Class

Module Example
   Public Sub Main()
      Dim t As Type = GetType(DerivedClass)
      Dim m, mb As MethodInfo
      Dim methodNames() As String = { "ToString", "Equals",
                                      "InterfaceImpl", "Method1",
                                      "Method2", "Method3" }

      For Each methodName In methodNames
         m = t.GetMethod(methodName)
         mb = m.GetBaseDefinition()
         Console.WriteLine("{0}.{1} --> {2}.{3}", m.ReflectedType.Name,
                           m.Name, mb.ReflectedType.Name, mb.Name)
      Next
   End Sub
End Module
開發者ID:VB.NET開發者,項目名稱:System.Reflection,代碼行數:56,代碼來源:MethodInfo.GetBaseDefinition

輸出:

DerivedClass.ToString --> Object.ToString
DerivedClass.Equals --> Object.Equals
DerivedClass.InterfaceImpl --> DerivedClass.InterfaceImpl
DerivedClass.Method1 --> BaseClass.Method1
DerivedClass.Method2 --> BaseClass.Method2
DerivedClass.Method3 --> DerivedClass.Method3

示例2: ReflectionUtilities

' 導入命名空間
Imports System.Reflection

Public Class ReflectionUtilities
   Public Shared Function IsOverride(method As MethodInfo) As Boolean
      Return Not method.Equals(method.GetBaseDefinition())
   End Function
End Class

Module Example
   Public Sub Main()
      Dim equals As MethodInfo = GetType(Int32).GetMethod("Equals", 
                                         { GetType(Object) } )
      Console.WriteLine("{0}.{1} is inherited: {2}", 
                        equals.ReflectedType.Name, equals.Name,
                        ReflectionUtilities.IsOverride(equals))
      
      equals = GetType(Object).GetMethod("Equals", { GetType(Object) } )
      Console.WriteLine("{0}.{1} is inherited: {2}", 
                        equals.ReflectedType.Name, equals.Name,
                        ReflectionUtilities.IsOverride(equals))
   End Sub
End Module
開發者ID:VB.NET開發者,項目名稱:System.Reflection,代碼行數:23,代碼來源:MethodInfo.GetBaseDefinition

輸出:

Int32.Equals is inherited: True
Object.Equals is inherited: False


注:本文中的System.Reflection.MethodInfo.GetBaseDefinition方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。