Simple Serialization DeSerialization
there is a need to Serialize an object.
1. sending it to the client so manipulate via javascript
2. persist the object to the database or any other file.
Here's some functions I use on a regular basis
public staticstring Serialize(object o)
{
if (o==null) { return string.Empty; }StringWriter writer = new StringWriter();
XmlSerializer xs = new XmlSerializer(o.GetType());
xs.Serialize(writer,o);
writer.Close();
return writer.ToString();
}
public static object DeSerialize(string s, Type t)
{
object ret;}
if (s==null) { return null; }
if (s.Length ==0) { return null; }
XmlSerializer xs = new XmlSerializer(t);
ret = xs.Deserialize(new StringReader(s) );
return ret;