DataContractSerializer 是一个可选的序列化器.如何让它选择退出? [英] DataContractSerializer is an opt-in serializer. How to make it Opt-Out?
问题描述
我继承了一些具有大量属性的类.我希望能够为 WCF
序列化它们.
I inherited some classes with a large number of attributes. I want to be able to serialize them for WCF
.
由于 DataContractSerializer
是一个可选的序列化程序,我需要用 DataMember
属性来装饰所有的属性,这在我看来有点麻烦.难道我没有其他办法,这样我就不必将 DataMember
添加到所有属性中吗?
As DataContractSerializer
is an opt-in serializer, I will need to decorate all the properties with DataMember
attribute, which seems to me a little cumbersome. Don't I have any other way around so that I don't have to add DataMember
to all the properties?
请注意,我的大部分属性都需要序列化.
Please note, most of my properties need to be serialized.
推荐答案
来自 dotnet 4.0 及更高版本,
您可以避免使用 [DataContract]
属性来使所有 public
数据成员成为 serializable
.
You can avoid the [DataContract]
attribute to make all the public
datamembers serializable
.
这篇关于DataContractSerializer 是一个可选的序列化器.如何让它选择退出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!