WPF

时间:2016-06-09 05:21:09

标签: c# wpf serialization enums

我一直在尝试序列化一个包含枚举的对象

 public EEEEEEE HandledAirlineCopyInd { get; set; }
    [XmlIgnore]
    public bool RRRRRRR{ get; set; }
    [XmlElement("MatchInfo", typeof(TTTTTTTTT), Order = 11)]
    [XmlElement("MessageInfo", typeof(YYYYYYYYY), Order = 11)]
    public object Item { get; set; }
    [XmlAttribute]
    public XXXXXXXX ModuleID { get; set; }
    [XmlElement(Order = 5)]

属性ModuleId是枚举

[Serializable]
[GeneratedCode("System.Xml", "4.0.30319.34283")]
[XmlType(Namespace = "http://VVVV/common/7/0")]
public enum XXXXXXXX 
{
    WM = 0,
    WT = 1,
    WI = 2,
}

当我尝试按如下方式序列化时,

XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
        XmlSerializer serializer = new XmlSerializer(objectToSerialize.GetType());
        MemoryStream ms = new MemoryStream();
        XmlWriterSettings settings = new XmlWriterSettings();
        settings.Indent = true;
        settings.OmitXmlDeclaration = omitDeclaration;
        settings.Encoding = encoding;
        XmlWriter writer = XmlWriter.Create(ms, settings);
        serializer.Serialize(writer, objectToSerialize, ns);
        string xmlString = encoding.GetString(ms.ToArray());
        string xmlStringCleaned = CleanInvalidXmlChars(xmlString);

它没有序列化。请指教。

0 个答案:

没有答案