By default, the DataContractSerializer serializes all publicly visible types. All public read/write properties and fields of the type are serialized.
You can change the default behavior by applying the DataContractAttribute and DataMemberAttribute attributes to the types and members This feature can be useful in situations in which you have types that are not under your control and cannot be modified to add attributes. The DataContractSerializer recognizes such "unmarked" types.
You can apply the DataContractAttribute and DataMemberAttribute attributes to explicitly control or customize the serialization of types and members. In addition, you can apply these attributes to private fields. However, even types that are not marked with these attributes are serialized and deserialized. The following rules and exceptions apply:
The DataContractSerializer infers a data contract from types without attributes using the default properties of the newly created types.
All public fields, and properties with public get and set methods are serialized, unless you apply the IgnoreDataMemberAttribute attribute to that member.
The serialization semantics are similar to those of the XmlSerializer.
Read-only fields, properties without a get or set method, and properties with internal or private set or get methods are not serialized. Such properties are ignored and no exception is thrown, except in the case of get-only collections.
XmlSerializer attributes (such as XmlElement, XmlAttribute, XmlIgnore, XmlInclude, and so on) are ignored.
To "opt out" of the serialization process for public members, properties, or fields, apply the IgnoreDataMemberAttribute attribute to that member.
Unmarked types (types without the DataContractAttribute attribute) can inherit from types that do have this attribute; however, the reverse is not permitted: types with the attribute cannot inherit from unmarked types. This rule is enforced primarily to ensure backward compatibility with code written in earlier versions of .NET Framework.