Reputation: 701
I Collected the info from one of the previous StackOverflow Q & A that
The following items can be serialized using the XmlSerializer
class:
My Question is how can we develop a XmlSerialize Helper class that takes a Generic Collection as parameter for Xml Serialization.
Upvotes: 2
Views: 4512
Reputation: 94645
http://www.codeproject.com/KB/XML/CustomXmlSerializer.aspx?msg=3101055
SUMMARY:CustomXmlSerializer is an alternative to XmlSerializer, supporting both shallow and deep serialization of ArrayLists, Collections, and Dictionaries.
Upvotes: 0
Reputation: 292425
public class XmlSerializationHelper
{
public static void Serialize<T>(string filename, T obj)
{
XmlSerializer xs = new XmlSerializer(typeof(T));
using (StreamWriter wr = new StreamWriter(filename))
{
xs.Serialize(wr, obj);
}
}
public static T Deserialize<T>(string filename)
{
XmlSerializer xs = new XmlSerializer(typeof(T));
using (StreamReader rd = new StreamReader(filename))
{
return (T)xs.Deserialize(rd);
}
}
}
(it's not specifically for generic collections, it works for any XML-serializable object)
I'm not sure if that's what you were looking for... if not, please detail what you need
Upvotes: 7