简体   繁体   English

在VB.NET中实现属性

[英]Implement properties in VB.NET

I have a class MyVisible having a property Visible . 我有一个MyVisible类具有Visible属性。

I have a class MySuperVisible implementing a interface ISuperVisible , that contains also property Visible . 我有一个类MySuperVisible实现了一个接口ISuperVisible ,它还包含属性Visible

How should I implement the "Visible" property of the interface "ISuperVisible" in "MySuperVisible" class? 我应该如何在“MySuperVisible”类中实现“ISuperVisible”接口的“Visible”属性?

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. PS。 MySuperVisible inherits MyVisible, so I need to implement a property that already exists in the base class. MySuperVisible继承了MyVisible,所以我需要实现一个已存在于基类中的属性。

Interesting question. 有趣的问题。 I think the Shadows keyword is probably the appropriate way to go here. 我认为Shadows关键字可能是适合的方式。 That makes things a little more explicit than PrivatePropertyPlaceholder : 这使事情比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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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