Example #1
0
        public static string SerializeObject <T>(T o)
        {
            StringWriter  sw = new StringWriter();
            XmlTextWriter tw = null;

            try
            {
                XmlSerializer serializer = new XmlSerializer(typeof(T));
                tw = new XmlTextWriter(sw);
                serializer.Serialize(tw, o);
            }
            finally
            {
                sw.Close();
                if (tw.IsNotNull())
                {
                    tw.Close();
                }
            }

            return(sw.ToString());
        }