It's a clever solution, but I'm wondering why XML should be used at all in this scenario? If the default serializer doesn't support IDictionary properly, why attempt to use it at all?
Using the JSON.NET library, dictionary objects can be serialized as JSON very easily. Dictionaries are easily represented in JSON, which is not the case with XML.
Would it be possible to extend this example in a way that JSON could be output rather than XML? I agree with you dpeterson, and think a lot of people will be alienated who are moving away from XML and into other serialization formats.
@dpeterson - actually I doubt you get two way serialization/deserialization of objects in JSON. It's not really possible given that no type information is available if you have Dictionary<string,object>. THere's no way for the deserializer to turn that back into the original dictionary unless type info is explicitly provided. There's more info on the post's comments about this.
Ah, I was working under the assumption that the object would be of a known type. Similar to how you would write code for mapping a DTO to your data layer and back. In this case you would just explicitly cast rather than storing any type information.
Using the JSON.NET library, dictionary objects can be serialized as JSON very easily. Dictionaries are easily represented in JSON, which is not the case with XML.