【发布时间】:2015-05-22 17:45:08
【问题描述】:
也许有人可以帮助我,我可以想象这是一个共同的需求: 我有一个基类和一个子类。基类有一个名为“hello”的属性。现在我需要在子属性 Set 中添加扩展功能 - 我该如何实现?
进一步解释的代码示例:
基类:
Public MustInherit Class Base
Private pHello as String = ""
Public Property Hello As String
Get
Return pHello
End Get
Set(ByVal value As String)
pHello = value
'DoSomethingInBaseClass()
MsgBox "BaseClass calling!" 'Just for testing
End Set
End Property
End Class
儿童班
Public Class Child
Inherits Base
Public Property Hello As String
Get
Return MyBase.Hello
End Get
Set(ByVal value As String)
'DoSomethingInCHILDClass()
MsgBox "ChildClass calling!" 'Just for testing
End Set
End Property
End Class
Main 中的属性集
Public Class Main
Public Sub DoIt()
Dim InstChild as new Child
InstChild.Hello = "test"
End Sub
End Class
基本上我想要的是,在设置属性时,我首先获得子消息框,然后是基本消息框。
当然我需要在属性定义中添加一个关键字。 我玩过 Shadows 和 Overrides,但要么只得到 Child,要么只得到 Base Message。
有没有办法两者兼得?
非常感谢!
【问题讨论】:
标签: vb.net inheritance properties expand