Is there a way to serialize key/value pairs (preferably strongly typed, but possibly also sourced from a Dictionary) into the desired format below?
public List<Identifier> Identifiers = new List<Identifiers>();
public class Identifier
{
public string Name { get; set; }
public string Description { get; set; }
}
This normally serializes to the following:
<Identifiers>
<Identifier>
<Name>somename</Name>
<Description>somedescription</Description>
</Identifier>
<Identifier>
...
</Identifier>
</Identifiers>
The other possible approach we were thinking about is to use a hashtable/dictionary:
public Dictionary<string, string> Identifiers = new Dictionary<string,string>
{
{ "somename", "somedescription"},
{ "anothername", "anotherdescription" }
};
But this will either require a custom serialized Dictionary, or a custom XmlWriter
.
The output we would like to achieve is:
<Identifiers>
<somename>somedescription</somename>
<anothername>anotherdescription</anothername>
</Identifiers>
So we're looking for code samples as to how best approach this to get the output we desire.
Edit: Maybe I should explain better. We already know how to serialize objects. What we are looking for is the answer to a particular type of serialization... I'll expand the question above