Can I fail to deserialize with XmlSerializer in C# if an element is not found?

后端 未结 3 1588
天命终不由人
天命终不由人 2020-11-30 11:19

I am using XmlSerializer to write and read an object to xml in C#. I currently use the attributes XmlElement and XmlIgnore to manipulate the seria

3条回答
  •  感情败类
    2020-11-30 11:49

    For extensibility reasons, XmlSerializer is very forgiving when it comes to deserialization; things like [DefaultValue], ShouldSerialize{Foo} and {Foo}Specified are mainly used during serialization (the exception being {Foo}Specified, which is set during deserialization as well as queried during serialization).

    As such; there isn't an easy way to do this, unless you implement IXmlSerializable and do it yourself. damagednoob shows an xsd option, which is also an option.

提交回复
热议问题