By all means put this in the codeplex project.
Serializing / Deserializing objects to XML:
/// Serializes an object of type T in to an xml string
/// Any class type
/// Object to serialize
/// A string that represents Xml, empty otherwise
public static string XmlSerialize(this T obj) where T : class, new()
{
if (obj == null) throw new ArgumentNullException("obj");
var serializer = new XmlSerializer(typeof(T));
using (var writer = new StringWriter())
{
serializer.Serialize(writer, obj);
return writer.ToString();
}
}
/// Deserializes an xml string in to an object of Type T
/// Any class type
/// Xml as string to deserialize from
/// A new object of type T is successful, null if failed
public static T XmlDeserialize(this string xml) where T : class, new()
{
if (xml == null) throw new ArgumentNullException("xml");
var serializer = new XmlSerializer(typeof(T));
using (var reader = new StringReader(xml))
{
try { return (T)serializer.Deserialize(reader); }
catch { return null; } // Could not be deserialized to this type.
}
}