Store a settings record in the user class. Serialize it for ease of loading / saving. Use this settings class for all storing / retrieving stuff. Works awesome.
This commit is contained in:
@ -12,7 +12,8 @@ using System.Drawing;
|
||||
using System.Media;
|
||||
using System.Reflection;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
using System.Xml.Serialization;
|
||||
using System.IO;
|
||||
|
||||
namespace EduNetworkBuilder
|
||||
{
|
||||
@ -367,6 +368,11 @@ namespace EduNetworkBuilder
|
||||
|
||||
public static NBSettings GetSettings()
|
||||
{
|
||||
//Try getting the user settings
|
||||
PersonClass User = GetUser();
|
||||
if (User != null) return User.UserSettings;
|
||||
|
||||
//If no user, get the settings for the program.
|
||||
BuilderWindow myWin = (BuilderWindow)Application.OpenForms["BuilderWindow"];
|
||||
if (myWin != null)
|
||||
{
|
||||
@ -580,6 +586,36 @@ namespace EduNetworkBuilder
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Serialize any serializable class to an XML string.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of object</typeparam>
|
||||
/// <param name="toSerialize">The object to serialize</param>
|
||||
/// <returns>A string containing the serialized object in XML</returns>
|
||||
public static string SerializeObject<T>(T toSerialize)
|
||||
{
|
||||
XmlSerializer xmlSerializer = new XmlSerializer(toSerialize.GetType());
|
||||
|
||||
using (StringWriter textWriter = new StringWriter())
|
||||
{
|
||||
xmlSerializer.Serialize(textWriter, toSerialize);
|
||||
return textWriter.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deserialize (oposite of SerializeObject) an object from an xml string.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of object to deserialize</typeparam>
|
||||
/// <param name="toDeserialize">the xml string containing the object</param>
|
||||
/// <returns>An object of the specified type</returns>
|
||||
public static T Deserialize<T>(string toDeserialize)
|
||||
{
|
||||
XmlSerializer xmlSerializer = new XmlSerializer(typeof(T));
|
||||
StringReader textReader = new StringReader(toDeserialize);
|
||||
return (T)xmlSerializer.Deserialize(textReader);
|
||||
}
|
||||
|
||||
public static List<string> GetPuzzleTags()
|
||||
{
|
||||
BuilderWindow myWin = (BuilderWindow)Application.OpenForms["BuilderWindow"];
|
||||
|
Reference in New Issue
Block a user