'Extend .NET XmlSerializer?

The question is simple as stated in the title.

I need to somehow extend the existing .NET XMLSerializer.

The reasons are

  • It already does so many things. I do not want to reinvent the wheel.
  • I need to deserialize a bunch of tags to a key/value pair. E.g.
<City>
    <Suburb1>Test1</Suburb1>
    <Suburb2>Test2</Suburb2>
</City>

This needs to be deserialized to

    `List<KeyValuePair<string,string>` suburbsList
     `suburbsList.Add(new KeyValuePair("Suburb1", "Test1"))
     `suburbsList.Add(new KeyValuePair("Suburb2", "Test2"))  

The example here is simplified, so having strongly typed properties is not an option.

I tried UnknownNode event from the XmlSerializer class but it does not seem to do what I'm intending. TBH, I have not explored a lot on this though.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source