1

In C#, I have a situation where I get a random XMLSchema and I need to find which class that it should be serialized into.

At the moment I have a hard coded switch that checks IDs and matches the class type. However this isnt very dynamic and needs to be changed every time a new XMLSchema is added. Im trying to think of a more dynamic approach.

My first thought would be to loop through the types to see which one matches. But im not sure if this is possible or if its even a good idea.

MichaelTaylor3D
  • 1,615
  • 3
  • 18
  • 32
  • How do you know that for a "random" schema, you will have a class that matches it? – vesan Jul 02 '14 at 22:40
  • Its random schema within a set of known schema. Basically, when I come across one, I currently have no way to associate it with the class that gets serialized into without hard coding that association. Unfortunately the cms I am using is forcing this type of design. Its not an ideal design. – MichaelTaylor3D Jul 03 '14 at 12:17
  • OK, I see. Take a look at these: http://stackoverflow.com/questions/4801215/how-do-i-use-an-xmlserializer-to-deserialize-an-object-that-might-be-of-a-base-o, http://stackoverflow.com/questions/8210386/deserialize-random-unknown-types-with-xmlserializer, http://stackoverflow.com/questions/775647/how-do-i-deserialize-xml-without-knowing-the-type-beforehand – vesan Jul 03 '14 at 22:19

0 Answers0