I like to use an XML serializable class since it is very easy to maintain and modify. Just add the attributes above the class and properties. Then you can just serialize to an XML and deserialize your XML to an object.
Example:
using System;
using System.IO;
using System.Xml.Serialization;
[XmlRoot("UserProfile")]
public class Profile
{
[XmlElement()]
public string Name { get; set; }
[XmlElement()]
public int Age { get; set; }
public void Serialize(string uri)
{
if (string.IsNullOrEmpty(uri))
throw new ArgumentNullException("File path invalid.");
XmlSerializer s = new XmlSerializer(typeof(Profile));
using (TextWriter w = new StreamWriter(uri))
{
s.Serialize(w, this);
w.Close();
}
}
public static Profile Deserialize(string uri)
{
if (string.IsNullOrEmpty(uri))
throw new ArgumentNullException("File path invalid.");
using (TextReader r = new StreamReader(uri))
{
XmlSerializer s = new XmlSerializer(typeof(Profile));
return (Profile)s.Deserialize(r);
}
}
}