开发者

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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜