是否有一个属性会隐式假定具有 DataContract 的类的所有成员都是数据成员?
是否有一种属性可以假设它是数据成员,而不是必须为每个成员指定 [DataMember]?
我有一个包含很多成员的类,我必须将它们序列化到 Web 服务中。
Instead of having to specify [DataMember] for every member, is there a sort of attribute that can just assume it is a datamember?
I have a class with a lot of members that I have to serialize into a web service.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 [Serialized] 来代替,但它会给您将来的版本控制带来麻烦。基本上放弃 [DataMember] 意味着您无法显式控制合约成员的序列化顺序,这意味着添加新成员很容易破坏现有客户端(因为默认的 WCF 行为是按字母顺序而不是声明顺序对成员进行排序) )。
You could use [Serializable] instead, but it's going to cause you trouble in the future for versioning. Basically giving up [DataMember] means you can't explicitly control serialization order for members of your contract, which means adding a new member can easily break existing clients (because of the default WCF behavior of ordering members in alphabetical order instead of order of declaration).