0

I have a class used to serialize and deserialize via XMLSerializer. ExportSteps is another class which implements IXmlSerializer for custom serialization.

My issue is it's not reading and setting any properties after it reads exportSteps. If I move IsNew and Test2 above Steps, it works fine. I don't think that is a valid solution though, what if I need two custom serialized classes?

public class PublishOptions
{


    [XmlElement( "test" )]
    public bool Test { get; set; }

    [XmlElement( "exportSteps" )]
    public ExportSteps Steps { get; set; } <-- implements IXmlSerializable

    [XmlElement( "isNew" )]
    public bool IsNew { get; set; }

    [XmlElement( "test2" )]
    public bool Test2{ get; set; }}
}

var test = serializer.Deserialize(stream) as PublishOptions;

XML (Example):

<publishingOptions>
  <test>true</test>
  <exportSteps>     
    <option>foo</option>
    <option>bar</option>
  </exportSteps>
  <isNew>true</isNew>
  <test2>true</test2>
</publishingOptions>
4

1 回答 1

0

我发现了错误,它在 ReadXml 方法中。阅读器在元素中间退出自定义阅读器。这导致自定义序列化程序失败后的任何事情。

于 2013-02-27T00:13:34.997 回答