Created
January 24, 2011 00:23
-
-
Save bojanrajkovic/792615 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.IO; | |
using System.Xml.Serialization; | |
using System.Collections.Generic; | |
namespace FlashDebugger | |
{ | |
public class Util | |
{ | |
public class SerializeXML<T> | |
{ | |
public static void SaveFile(string filename, T obj) | |
{ | |
XmlSerializer serializer1 = new XmlSerializer(typeof(T)); | |
FileStream fs1 = new FileStream(filename, FileMode.Create); | |
serializer1.Serialize(fs1, obj); | |
fs1.Close(); | |
} | |
public static T LoadFile(string filename) | |
{ | |
XmlSerializer serializer2 = new XmlSerializer(typeof(T)); | |
FileStream fs2 = new FileStream(filename, FileMode.Open); | |
T loadClasses = (T)serializer2.Deserialize(fs2); | |
fs2.Close(); | |
return loadClasses; | |
} | |
public static T LoadString(string s) | |
{ | |
XmlSerializer serializer = new XmlSerializer(typeof(T)); | |
StringReader str = new StringReader(s); | |
T loadClasses = (T)serializer.Deserialize(str); | |
str.Close(); | |
return loadClasses; | |
} | |
} | |
} | |
} | |
namespace Test | |
{ | |
using FlashDebugger; | |
public class TestClass | |
{ | |
public static void Main (string[] args) { | |
List<int> l = new List<int> { 1, 2, 3, 4, 5, 6, 7, 8, 9, 100 }; | |
Util.SerializeXML<List<int>>.SaveFile("test.xml", l); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment