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


VB.NET MethodBase.IsHideBySig屬性代碼示例

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


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

示例1: Test

' 導入命名空間
Imports System.Reflection

' The base class B contains an overloaded method M.
'
Public Class B
    Public Overridable Sub M()
        Console.WriteLine("B's M()")
    End Sub
    Public Overridable Sub M(ByVal x As Integer)
        Console.WriteLine("B's M({0})", x)
    End Sub
End Class

' The derived class D hides the inherited method M.
'
Public Class D
    Inherits B
    Shadows Public Sub M(ByVal i As Integer)
        Console.WriteLine("D's M({0})", i)
    End Sub
End Class

Public Class Test
    Public Shared Sub Main()
        Dim dinst As New D()
        ' In Visual Basic, the method in the derived class hides by
        ' name, rather than by signature.  Thus, although a list of all the 
        ' overloads of M shows three overloads, only one can be called from
        ' class D.  
        '
        Console.WriteLine("------ List the overloads of M in the derived class D ------")
        Dim t As Type = dinst.GetType()
        For Each minfo As MethodInfo In t.GetMethods()
            If minfo.Name = "M" Then Console.WriteLine( _
                "Overload of M: {0}  IsHideBySig = {1}, DeclaringType = {2}", _
                minfo, minfo.IsHideBySig, minfo.DeclaringType)
        Next

        ' The method M in the derived class hides the method in B.
        '
        Console.WriteLine("------ Call the overloads of M available in D ------")
        ' The following line causes a compile error, because both overloads
        ' in the base class are hidden.  Contrast this with C#, where only 
        ' one of the overloads of B would be hidden.
        'dinst.M()
        dinst.M(42)
        
        ' If D is cast to the base type B, both overloads of the 
        ' shadowed method can be called.
        '
        Console.WriteLine("------ Call the shadowed overloads of M ------")
        Dim binst As B = dinst
        binst.M()
        binst.M(42)         
    End Sub
End Class
開發者ID:VB.NET開發者,項目名稱:System.Reflection,代碼行數:57,代碼來源:MethodBase.IsHideBySig

輸出:

------ List the overloads of M in the derived class D ------
Overload of M: Void M(Int32)  IsHideBySig = False, DeclaringType = B
Overload of M: Void M()  IsHideBySig = False, DeclaringType = B
Overload of M: Void M(Int32)  IsHideBySig = False, DeclaringType = D
------ Call the overloads of M available in D ------
D's M(42)
------ Call the shadowed overloads of M ------
B's M()
B's M(42)


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