覆盖 VB.NET 中的事件
我想隐藏/覆盖 VB.NET 中的事件。
我这样做只是因为我必须在此对象中实现一个接口,该接口包含与基础对象本身相同的事件,并且我需要保持此基础事件不变,无需修改,也无需添加补充事件。
我该怎么做呢?
Public Shadows Event VisibleChanged As EventHandler Implements IVisibleChanged
因此,我想实现一个包含 VisibleChanged 事件的接口,但也要保持 myBase VisibleChanged 事件的功能。
Public Shadows Event VisibleChanged As EventHandler Implements IVisibleChanged
AddHandler(ByVal value As EventHandler)
AddHandler MyBase.VisibleChanged, value
End AddHandler
RemoveHandler(ByVal value As EventHandler)
RemoveHandler MyBase.VisibleChanged, value
End RemoveHandler
End Event
像这样的东西,但 Visual Studio 似乎无法识别这样的语法...
我的意思是,在 C# 中我是这样实现的:
public new event EventHandler VisibleChanged
{
add { base.VisibleChanged += value; }
remove { base.VisibleChanged -= value; }
}
I would like to shadow/override an event in VB.NET.
I do it only because I have to implement in this object an interface, that contains the same event like the base object itself, and I need to keep this base event as is it without modification nor supplementary event additions.
How can I do it?
Public Shadows Event VisibleChanged As EventHandler Implements IVisibleChanged
So, I would like to implement a interface that contains VisibleChanged event, but to keep functional the myBase VisibleChanged event too.
Public Shadows Event VisibleChanged As EventHandler Implements IVisibleChanged
AddHandler(ByVal value As EventHandler)
AddHandler MyBase.VisibleChanged, value
End AddHandler
RemoveHandler(ByVal value As EventHandler)
RemoveHandler MyBase.VisibleChanged, value
End RemoveHandler
End Event
something like this, but it seems Visual Studio does not recognize such a syntax...
I mean, in C# I realize it like this:
public new event EventHandler VisibleChanged
{
add { base.VisibleChanged += value; }
remove { base.VisibleChanged -= value; }
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以重写派生类中的处理程序吗?
Can you override the handler in a derived class?
像这样的东西,但 Visual Studio 似乎无法识别这样的语法...
我的意思是,在 C# 中我是这样实现的:
something like this, but it seems Visual Studio does not recognize such a syntax...
I mean, in C# I realize it like this:
在 VB.NET 中实现接口时,不需要将实现命名为与接口相同的名称。
接口示例:
实现示例:
当某人作为 IFoo 附加到您时,他们将获得您的 IFooBar 事件:
当他们作为 FooImplementation 附加到您时,他们将获得 Bar 事件,并且他们还能够附加到 IFooBar :
When implementing an interface in VB.NET, you don't need to name the implementation the same name as the interface.
Example interface:
Example implementation:
When somebody is attached to you as an IFoo, they will get your IFooBar event:
When they're attached to you as FooImplementation, they'll get the Bar event and they will also be able to attach to IFooBar: