Sometimes I want to emulate stored data of my classes without setting up a round trip to the database. For example, let\'s say I have the following classes:
Nicely done. Here is the example to serialize plain POCO to string.
private string poco2Xml(object obj)
{
XmlSerializer serializer = new XmlSerializer(obj.GetType());
StringBuilder result = new StringBuilder();
using (var writer = XmlWriter.Create(result))
{
serializer.Serialize(writer, obj);
}
return result.ToString();
}