Esempio n. 1
0
        public static XmlDocument SerializeAsXmlDoc(Object obj, Type[] extraTypes = null)
        {
            if (obj == null)
            {
                return(null);
            }

            var sw            = new StringWriter();
            var xmlTextWriter = new CustomXmlTextWriter(sw);

            var serializer = extraTypes != null ? new XmlSerializer(obj.GetType(), extraTypes) : new XmlSerializer(obj.GetType());

            serializer.Serialize(xmlTextWriter, obj);

            var doc = new XmlDocument();

            doc.LoadXml(sw.ToString());

            return(doc);
        }
Esempio n. 2
0
        public static XmlDocument SerializeAsXmlDoc(Object obj)
        {
            if (obj == null)
            {
                return(null);
            }

            StringWriter        sw            = new StringWriter();
            CustomXmlTextWriter xmlTextWriter = new CustomXmlTextWriter(sw);

            XmlSerializer serializer = new XmlSerializer(obj.GetType());

            serializer.Serialize(xmlTextWriter, obj);

            XmlDocument doc = new XmlDocument();

            doc.LoadXml(sw.ToString());

            return(doc);
        }