Handy C# XML Serialization Methods

I have been hacking away on WPF/MVVM, GWT/MVP, and Rails for the last six months and haven't found much time to update. But I wrote some handy C# XML serialization methods. They are very straightforward.


public static T ReadFromFile(string file) {
    XmlSerializer xs = new XmlSerializer(typeof(T));
    StreamReader sr = new StreamReader(file);
    T ret = (T)xs.Deserialize(sr);
    return ret;


public static void WriteToFile(T obj, string file) {
    XmlSerializer xs = new XmlSerializer(typeof(T));
    StreamWriter sw = new StreamWriter(file);
    xs.Serialize(sw, obj);


If you made it this far, you should follow me on Twitter.


Want to test-drive Bitcoin without any risk? Check out my bitcoin wallet Coinbolt. It includes test coins for free.

comments powered by Disqus