If you use the default serialization XmlSerializer
(not IXmlSerializable
), then itβs valid: this cannot be achieved without adding an extra class, which is AlertOne
, with the attribute and value [XmlText]
.
If you implement IXmlSerializable
, this should be possible, but it is not a very good interface for a reliable implementation (deserialization, in particular, is difficult if it is only for writing, then it should be good). Personally, I would recommend matching the DTO model with the above-mentioned extra class.
Other tools, such as LINQ-to-XML, will make it pretty simple, but work differently.
An example of a suitable DTO layout:
public class Alerts { [XmlElement("AlertOne")] public Alert AlertOne { get; set; } } public class Alert { [XmlText] public int Parameter { get; set; } [XmlAttribute("Enabled")] public bool Enabled { get; set; } }
You could, of course, add a few members of the [XmlIgnore]
pass-thru that talk to the internal instance.
source share