i'm serialization a class but i can't exclude some field in my class.
[Serializable]
public class DicData
{
private GDicJson DeserializedGDicJson = new GDicJson();
public UOCDicData BuiltDicData;
[NonSerialized]
public string CacheName = "";
}
in my expection, a public field CacheName didn't include in my *.xml deserialized output, but it included in .xml file.
here are serializing rutine.
XmlSerializer myXml = new XmlSerializer(typeof(DicData), "test");
myXml.Serialize(myFile, this); //note:a serializing perform in method of himself.
For XmlSerializer
you want
[XmlIgnore]
Also, note that the [Serializable]
is unnecessary in this case.
As a final note: public fields are not encouraged; properties are almos always preferred. The addition of {get;set;}
would go a long way...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With