How do I replace the names of entries in a collection?
By default the names inside of a collection are based on the type or role of the entry.
<CheeseMap> <KeyValueOfstringCheeseListLjh4bohd> <Key>Sweden</Key> <Value> <string>Adelost</string> <string>Graddost</string> <string>Vasterbottenost</string> </Value> </KeyValueOfstringCheeseListLjh4bohd></CheeseMap>
This provides a certain style of object serialization that is very utilitarian but is not what a format that was crafted by hand has probably picked. People generally like to pick names that describe what an entry is rather than what it does.
You can replicate the particular format names of a collection by using the CollectionDataContract attribute to customize serialization. Ordinarily, collections just work together with serialization through the magic of defaults. CollectionDataContract only shows up in these situations where the defaults are not what you want.
Four changes you might want to make are:
Putting together those changes, we go from the previous example into this:
<CheeseMap> <CheeseRegion> <Country>Sweden</Country> <Cheeses> <Cheese>Adelost</Cheese> <Cheese>Graddost</Cheese> <Cheese>Vasterbottenost</Cheese> </Cheeses> </CheeseRegion></CheeseMap>
Interesting Finds: June 12, 2009