简体   繁体   中英

Implement properties in VB.NET

I have a class MyVisible having a property Visible .

I have a class MySuperVisible implementing a interface ISuperVisible , that contains also property Visible .

How should I implement the "Visible" property of the interface "ISuperVisible" in "MySuperVisible" class?

Class MySuperVisible
  Inherits MyVisible
  Implements ISuperVisible

... 

Private Property PrivatePropertyPlaceholder Implements ISuperVisible.Visible
  Get
    Return MyBase.Visible
  End Get
  Set
    MyBase.Visible = value
  End Set
End Property

is implementing a private property the only solution to do it?

PS. MySuperVisible inherits MyVisible, so I need to implement a property that already exists in the base class.

Interesting question. I think the Shadows keyword is probably the appropriate way to go here. That makes things a little more explicit than PrivatePropertyPlaceholder :

Public Shadows Property Visible As Boolean Implements ISuperVisible.Visible
    Get
        Return MyBase.Visible
    End Get
    Set(value As Boolean)
        MyBase.Visible = value
    End Set
End Property

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM