TryXmlSerialize function

I was using XmlSerialize method from 

http://codebetter.com/blogs/brendan.tompkins/archive/2005/03/01/56244.aspxfor 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;
    }
I've also found useful to specify inside XmlSerialize
writer.Formatting = Formatting.Indented;
 
 
posted @ Sunday, March 22, 2009 10:17 AM
Print

Comments on this entry:

No comments posted yet.

Your comment:



(not displayed)

 
 
 
 
 

Live Comment Preview:

 
«April»
SunMonTueWedThuFriSat
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910