How to specify a NonSerialized field with public accessors for XML Serialization
How do you specify a NonSerialized field with pu开发者_StackOverflowblic accessors for XML Serialization?
[NonSerialized]
public String _fooBar;
//Declaring the property here will serialize the _fooBar field
public String FooBar
{
get { return _fooBar; }
set { _fooBar = value; }
}
Properties don't get serialized by BinaryFormatter
, only fields. The [NonSerialized]
attribute has no meaning for XML serialization. Use [XmlIgnore]
instead.
精彩评论