Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify a NonSerialized field with public accessors for XML Serialization

How do you specify a NonSerialized field with public 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; }
}
like image 463
MPelletier Avatar asked Apr 06 '11 01:04

MPelletier


1 Answers

Properties don't get serialized by BinaryFormatter, only fields. The [NonSerialized] attribute has no meaning for XML serialization. Use [XmlIgnore] instead.

like image 196
Hans Passant Avatar answered Oct 23 '22 00:10

Hans Passant