Blogger :
Michael Freidgeims Blog
All posts :
All posts by Michael Freidgeims Blog
Category :
XML
Blogged date : 2009 Mar 21
I was using XmlSerialize method from http://serialization.codebetter.com/blogs/brendan.tompkins/archive/2005/03/01/56244.aspx
for a while.
Recently I found that sometimes it's safer to use TryXmlSerialize:
/// <summary>
/// Serialize an object into XML
/// </summary>
/// <param name="serializableObject">Object that can be serialized</param>
/// <returns>Serial XML representation</returns>
public static bool TryXmlSerialize(object objectToSerialize, out string strXml)
{
bool bRet=true;
try
{
strXml =XmlSerialize( objectToSerialize);
}
catch (Exception exc)
{
bRet=false;
strXml=exc.ToString();
}
return bRet;
}
