Geeks With Blogs

Michael Freidgeim's Blog MS .Net Development
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 on Sunday, March 22, 2009 10:17 AM .Net Framework | Back to top


Comments on this post: TryXmlSerialize function

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Michael Freidgeim | Powered by: GeeksWithBlogs.net | Join free