- Main Page
- Classes
- Files

- File List

# C:/Users/Andreas Schiffler/Desktop/SVN/NewGamePhysics/NewGamePhysics/Networking/InfoLinkSerializer.cs

    00001 ﻿//-----------------------------------------------------------------------------
    00002 // InfoLinkSerializer.cs
    00003 // (A. Schiffler, 2009)
    00004 //-----------------------------------------------------------------------------
    00005
    00006 namespace NewGamePhysics.Networking
    00007 {
    00008     using System;
    00009     using System.IO;
    00010     using System.Text;
    00011     using System.Xml;
    00012     using System.Collections.Generic;
    00013     using System.Xml.Serialization;
    00014
    00018     public class InfoLinkSerializer
    00019     {
    00025         public static string Serialize(InfoLink infoLink)
    00026         {
    00027             string xmlText = string.Empty;
    00028             XmlSerializer xmlSerializer = new XmlSerializer(typeof(InfoLink));
    00029             StringBuilder xmlSb = new StringBuilder();
    00030             TextWriter textWriter = new StringWriter(xmlSb);
    00031             xmlSerializer.Serialize(textWriter, infoLink);
    00032             xmlText = xmlSb.ToString();
    00033             return xmlText;
    00034         }
    00035
    00041         public static string SerializeArray(InfoLink[] infoLinks)
    00042         {
    00043             string xmlText = string.Empty;
    00044             XmlSerializer xmlSerializer = new XmlSerializer(typeof(InfoLink[]));
    00045             StringBuilder xmlSb = new StringBuilder();
    00046             TextWriter textWriter = new StringWriter(xmlSb);
    00047             xmlSerializer.Serialize(textWriter, infoLinks);
    00048             xmlText = xmlSb.ToString();
    00049             return xmlText;
    00050         }
    00051
    00057         public static InfoLink Deserialize(string xmlText)
    00058         {
    00059             XmlSerializer xmlSerializer = new XmlSerializer(typeof(InfoLink));
    00060             TextReader textReader = new StringReader(xmlText);
    00061             InfoLink infoLink = (InfoLink)xmlSerializer.Deserialize(textReader);
    00062             return infoLink;
    00063         }
    00064
    00070         public static InfoLink[] DeserializeArray(string xmlText)
    00071         {
    00072             XmlSerializer xmlSerializer = new XmlSerializer(typeof(InfoLink));
    00073             TextReader textReader = new StringReader(xmlText);
    00074             XmlTextReader xmlReader = new XmlTextReader(textReader);
    00075             xmlReader.Normalization = true;
    00076             List<InfoLink> infoLinks = new List<InfoLink>();
    00077             while (!xmlReader.EOF && xmlReader.ReadToFollowing("InfoLink"))
    00078             {
    00079                 InfoLink newInfoLink = (InfoLink)xmlSerializer.Deserialize(xmlReader);
    00080                 infoLinks.Add(newInfoLink);
    00081             }
    00082
    00083             return infoLinks.ToArray();
    00084         }
    00085     }
    00086 }
    00087