Наследование: System.Runtime.Serialization.XmlObjectSerializer
Пример #1
0
 public void SerializeToStream(object obj, Stream stream)
 {
     using (var xw = XmlWriter.Create(stream, XmlWriterSettings))
     {
         var ser = new XmlSerializerWrapper(obj.GetType());
         ser.WriteObject(xw, obj);
     }
 }
Пример #2
0
        public string SerializeToString <XmlDto>(XmlDto from)
        {
            try
            {
                using (var ms = MemoryStreamFactory.GetStream())
                {
                    using (XmlWriter xw = XmlWriter.Create(ms, XmlWriterSettings))
                    {
                        var ser = new XmlSerializerWrapper(from.GetType());
                        ser.WriteObject(xw, from);
                    }

                    return(ms.ReadToEnd());
                }
            }
            catch (Exception ex)
            {
                throw new SerializationException($"Error serializing object of type {from.GetType().FullName}", ex);
            }
        }
 public string Parse <XmlDto>(XmlDto from)
 {
     try
     {
         using (var ms = new MemoryStream())
         {
             using (XmlWriter xw = new XmlTextWriter(ms, Encoding.UTF8))
             {
                 var ser = new XmlSerializerWrapper(from.GetType());
                 ser.WriteObject(xw, from);
                 xw.Flush();
                 ms.Seek(0, SeekOrigin.Begin);
                 using (var reader = new StreamReader(ms))
                 {
                     return(reader.ReadToEnd());
                 }
             }
         }
     }
     catch (Exception ex)
     {
         throw new SerializationException(string.Format("Error serializing object of type {0}", from.GetType().FullName), ex);
     }
 }
Пример #4
0
        public string SerializeToString <XmlDto>(XmlDto from)
        {
            try
            {
                using (var ms = MemoryStreamFactory.GetStream())
                {
                    using (XmlWriter xw = XmlWriter.Create(ms))
                    {
                        var ser = new XmlSerializerWrapper(from.GetType());
                        ser.WriteObject(xw, from);
                    }

                    ms.Position = 0;
                    using (var reader = new StreamReader(ms))
                    {
                        return(reader.ReadToEnd());
                    }
                }
            }
            catch (Exception ex)
            {
                throw new SerializationException(string.Format("Error serializing object of type {0}", from.GetType().FullName), ex);
            }
        }