Friday, 26 October 2012
Small code snippents - ObjectToString
Sometimes is useful to display your object.
I wanted to display not only one item from object but whole object. Those can be quite big and not pleasant to display.
I have been pointed to the way, why not display it as xml.
and from this this came idea for this static serialize object.
So far i had no problem with this class. There is no exception trap, in order to let me know when some code has failed.
Nice class that I am using
public static string SerializeToString(object obj)
{
XmlSerializer serializer = new XmlSerializer(obj.GetType());
using (StringWriter writer = new StringWriter())
{
serializer.Serialize(writer, obj);
return writer.ToString();
}
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment