vb.net 事件声明 - 添加非序列化属性 [英] vb.net event declaration - adding nonserialized attribution

查看:23
本文介绍了vb.net 事件声明 - 添加非序列化属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在向现有的 c# 应用程序添加一个 vb.net 程序集.
我所有的 vb.net 类型都继承自:

I'm adding a vb.net assembly to existing c# application.
All of my vb.net types inherit from:

<Serializable()> _
Public Class BaseObject Implements INotifyPropertyChanged

    Public Event PropertyChanged as PropertyChangedEventHandler

    'Other helper methods'
End Class

我的问题是事件无法序列化.在 C# 代码中,事件声明如下:

My problem is that the event can not be serialized. In c# code, the event is declared like this:

 [field: NonSerialized]
 public event PropertyChangedEventHandler PropertyChanged;

但是我看不到如何使用 vb.net 以任何方式执行此操作.是否有可用于使事件不序列化的扩展事件声明?还是其他归因?

But I can not see how to do this in any way with vb.net. Is there extended event declaration that I can use to make the event not serialize? Or other attribution?

推荐答案

如果您使用的是 Visual Basic 10(与 Visual Studio 2010 一起提供),您可以添加 NonSerializedAttribute 到事件,就像在 C# 中一样.例如:

If you're using Visual Basic 10 (as shipped with Visual Studio 2010), you can add the NonSerializedAttribute to the event, just like you would in C#. For example:

<Serializable()> _
Public Class BaseObject Implements INotifyPropertyChanged

    <NonSerialized()> _
    Public Event PropertyChanged as PropertyChangedEventHandler

    'Other helper methods'
End Class

否则,事情会变得更加困难.您必须自己完成所有的跑腿工作,而不仅仅是将其留给编译器.有关详细信息和分步实施建议,请参阅本文.

Otherwise, things get a little more difficult. You have to do all of the legwork yourself instead of just leaving it to the compiler. See this article for more details and step-by-step implementation suggestions.

这篇关于vb.net 事件声明 - 添加非序列化属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆