Ejemplo n.º 1
0
        public static T Deserialize <T>(this XElement source) where T : class
        {
            try
            {
                var serializer = XmlSerializerFactory.GetSerializerFor(typeof(T));

                return((T)serializer.Deserialize(source.CreateReader()));
            }
            catch //(Exception x)
            {
                return(null);
            }
        }
Ejemplo n.º 2
0
        public static XElement Serialize(this object source)
        {
            try
            {
                var serializer = XmlSerializerFactory.GetSerializerFor(source.GetType());
                var xdoc       = new XDocument();
                using (var writer = xdoc.CreateWriter())
                {
                    serializer.Serialize(writer, source, new XmlSerializerNamespaces(new[] { new XmlQualifiedName("", "") }));
                }

                return((xdoc.Document != null) ? xdoc.Document.Root : new XElement("Error", "Document Missing"));
            }
            catch (Exception x)
            {
                return(new XElement("Error", x.ToString()));
            }
        }