C#C
C#3y ago
Sparky

❔ Is there an easy way to serialize a Dictionary<string, string> to XML nodes?

I'm writing a program that has to produce the following XML:
<Attributes>
    <Color>red</Color>
    <Size>small</Size>
    <Material>plastic</Material>
</Attributes>

I'm trying to figure out the best data model that can be serialized to something like this. The most obvious choice seems to be a Dictionary<string, string>, but I can also use a custom class with two properties (Name, Value). I've seen some solutions on stack overflow, but all of them involve creating a bunch of helper classes and writing hundreds of lines of additional code, and I refuse to believe that there is no simpler way of doing this, with Xml attributes or something like that.
Was this page helpful?