I have a class:
public class Car {
public string Model {get;set;}
public string SeatFinish {get;set;}
public string Audio {get;set;}
}
I want to use XML serialization attributes to serialize it to the following xml
<Car>
<Model>name</Model>
<Options>
<SeatFinish>Leather</SeatFinish>
<Audio>5 speaker</Audio>
</Options>
</Car>
For reasons specific to the project i cannot just create a property:
public List<string> Options;
Is there a way of specifying via attributes that a property is to be serialised under a certain xml Element (in this case an "Options" node)? Can I write a custom attribute that allows this? Any advice appreciated.
edit:
I see that having an options class will work but is there someway to acheive this without creating other classes? for example i might want to do this with only one property.
ideally i'd like to be able to specify
[Parent("Options")]
public string SeatFinish {get;set;}