I have some class,fox example
public class Test
{
[XmlElement(IsNullable = true)]
public string SomeProperty{get;set;}
}
When I serialize object of this class,I get
<test>
<SomeProperty>value<someproperty>
<test>
But I need add attribute to SomeProperty without changing structure of class and get this
<test>
<SomeProperty Search="true">value<someproperty>
<test>
How can I do that?
PS:I know,that i can write object that include "SomeProperty" and Bool property "Search",but it will change structure of class
To do that with XmlSerializer, you would need to have a second type with an [XmlAttribute] an [XmlText]. The only other option is IXmlSerializable, which is: a lot of work and easy to get wrong.
Options:
SomePropertySomeProperty - and mark SomeProperty as [XmlIgnore]IXmlSerializable (ouch)XmlSerializer at all (looking at LINQ-to-XML or a DOM, for example)XmlSerializer, but edit the xml afterwards (for example via a DOM or xslt)If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With