comp380team3 / PuzzlePathDimension

Class project for COMP 380 at California State University, Northridge
0 stars 0 forks source link

Implement a serializable UserProfile class #76

Closed Twisol closed 11 years ago

Twisol commented 11 years ago

This class provides the basic functionality for persisting a user's progress through the game, as well as their option preferences. It uses the .NET Framework's XML serialization facility, provided by System.Xml.Serialization and the XmlSerializer class. Any future persisted data should follow the approach here.

Example of loading a UserProfile:

XmlSerializer serializer = new XmlSerializer(typeof(UserProfile));

UserProfile profile = null;
using (XmlReader reader = new XmlTextReader("Content/profile.xml")) {
  profile = (UserProfile)serializer.Deserialize(reader);
}

Saving a UserProfile:

using (XmlWriter writer = new XmlTextWriter("Content/profile.xml", System.Text.Encoding.UTF8)) {
  serializer.Serialize(writer, profile);
}