Projekt

Obecné

Profil

Stáhnout (1.25 KB) Statistiky
| Větev: | Tag: | Revize:
1
using System;
2
using System.Collections.Generic;
3
using System.IO;
4
using System.Linq;
5
using System.Text;
6
using System.Threading.Tasks;
7
using System.Xml.Serialization;
8

    
9
namespace ServerApp.Connection.XMLProtocolHandler
10
{
11
    public class XmlCommunication
12
    {
13
        public static string Serialize<T>(T toSerialize)
14
        {
15
            var xml = new XmlSerializer(toSerialize.GetType());
16

    
17
            using (var stream = new StringWriter())
18
            {
19
                xml.Serialize(stream, toSerialize);
20
                return stream.ToString();
21
            }
22
        }
23

    
24
        //public static T Deserialize<T>(T toDeserialize, string xmlString)
25
        //{
26
        //    using (var stream = new StringReader(xmlString))
27
        //    {
28
        //        var xml = new XmlSerializer(toDeserialize.GetType());
29
        //        T deserialized = (T)xml.Deserialize(stream);
30
        //        return deserialized;
31
        //    }
32
        //}
33

    
34
        public static T Deserialize<T>(string xmlString)
35
        {
36
            using (var stream = new StringReader(xmlString))
37
            {
38
                var xml = new XmlSerializer(typeof(T));
39
                T deserialized = (T)xml.Deserialize(stream);
40
                return deserialized;
41
            }
42
        }
43

    
44
    }
45
}
(7-7/7)