A
Ayende Rahien
I've a Hashtable in my app, that contain string as keys, and a class created
by xsd schema.
According to what I saw while googling Hashtable:
A>Absolutely impossible to serialize.
B>Possible, but with the correct datatype.
Anyway, it didn't work, so I turned to another solution, I copied all the
keys & values to two ArrayLists and tried to serialize them one after
another.
That didn't work too well either, because then XmlSerializer exceptioned
complaining about not knowing about my custom class statically.
Then I did this:
XmlSerializer xs = new XmlSerializer(typeof(String[]));
xs.Serialize(sw,(string[])KeyList.ToArray(typeof(string)));
XmlSerializer xs = new XmlSerializer(typeof(Custom[]));
xs.Serialize(sw,(Custom[])KeyList.ToArray(typeof(Custom)));
Which works without throwing exception, except that it doesn't generate
valid XML (there is a secod XML declaration).
What is the proper way to do this?
How do I serialize several objects into one stream, when they of different
types?
Is there a way to directly serialize the Hashtable, which would be the
optimal solution for me.
by xsd schema.
According to what I saw while googling Hashtable:
A>Absolutely impossible to serialize.
B>Possible, but with the correct datatype.
Anyway, it didn't work, so I turned to another solution, I copied all the
keys & values to two ArrayLists and tried to serialize them one after
another.
That didn't work too well either, because then XmlSerializer exceptioned
complaining about not knowing about my custom class statically.
Then I did this:
XmlSerializer xs = new XmlSerializer(typeof(String[]));
xs.Serialize(sw,(string[])KeyList.ToArray(typeof(string)));
XmlSerializer xs = new XmlSerializer(typeof(Custom[]));
xs.Serialize(sw,(Custom[])KeyList.ToArray(typeof(Custom)));
Which works without throwing exception, except that it doesn't generate
valid XML (there is a secod XML declaration).
What is the proper way to do this?
How do I serialize several objects into one stream, when they of different
types?
Is there a way to directly serialize the Hashtable, which would be the
optimal solution for me.