Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NonSerialized dind't work

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.
like image 675
mjk6026 Avatar asked Dec 03 '22 01:12

mjk6026


1 Answers

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...

like image 168
Marc Gravell Avatar answered Dec 14 '22 10:12

Marc Gravell