使用 DataContractSerializer 进行序列化时如何忽略属性? [英] How can I ignore a property when serializing using the DataContractSerializer?
问题描述
我使用 .NET 3.5SP1 和 DataContractSerializer
来序列化一个类.在 SP1 中,他们更改了行为,因此您不必在类中包含 DataContract
/DataMember
属性,它只会序列化整个事物.这是我正在使用的行为,但现在我需要忽略序列化程序中的一个属性.我知道这样做的一种方法是将 DataContract
属性添加到类,然后将 DataMember
属性放在我想要包含的所有成员上.不过,我有理由认为这对我不起作用.
I am using .NET 3.5SP1 and DataContractSerializer
to serialize a class. In SP1, they changed the behavior so that you don't have to include DataContract
/DataMember
attributes on the class and it will just serialize the entire thing. This is the behavior I am using, but now I need to ignore one property from the serializer. I know that one way to do this is to add the DataContract
attribute to the class, and just put the DataMember
attribute on all of the members that I want to include. I have reasons, though, that this will not work for me.
所以我的问题是,是否有一个属性或什么东西可以用来让 DataContractSerializer
忽略一个属性?
So my question is, is there an attribute or something I can use to make the DataContractSerializer
ignore a property?
推荐答案
您可能正在寻找 IgnoreDataMemberAttribute
.
You might be looking for IgnoreDataMemberAttribute
.
这篇关于使用 DataContractSerializer 进行序列化时如何忽略属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!