How can I ignore a property when serializing using the DataContractSerializer?

NotDan picture NotDan · Nov 24, 2009 · Viewed 165.8k times · Source

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.

So my question is, is there an attribute or something I can use to make the DataContractSerializer ignore a property?

Answer

Paul Ruane picture Paul Ruane · Nov 24, 2009

You might be looking for IgnoreDataMemberAttribute.