Here is my code:
public static class SerializationUtil
{
public static string Serialize(object obj)
{
if (obj == null)
return string.Empty;
StringWriter writer = new StringWriter();
new System.Web.UI.LosFormatter().Serialize(writer, obj);
return writer.ToString();
}
public static object Deserialize(string data)
{
if (data == null)
return null;
return (new System.Web.UI.LosFormatter()).Deserialize(data);
}
}
The problem I am having is: When I call the serialize method if the obj is null it throws an error. So i would like to check if the obj value is null or not. The code I have i place now does not work as when the obj value is checked its never null.
Resolved:
See my post in answers
Serializegenerates an empty string instead of null, perhapsDeserializeshould accept an empty string in addition to null.