preferences now use object as type for serialization and no longer uses marker interface.
This commit is contained in:
@@ -1,13 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace RecrownedAthenaeum.Persistence
|
||||
{
|
||||
public interface Preferences
|
||||
{
|
||||
}
|
||||
}
|
@@ -8,15 +8,15 @@ namespace RecrownedAthenaeum.Persistence
|
||||
{
|
||||
public class PreferencesManager
|
||||
{
|
||||
private readonly Dictionary<Type, Preferences> preferenceList;
|
||||
private readonly Dictionary<Type, object> preferenceList;
|
||||
string savePath;
|
||||
XmlSerializer xmlSerializer;
|
||||
|
||||
public PreferencesManager(string savePath, params Preferences[] preferences)
|
||||
public PreferencesManager(string savePath, params object[] preferences)
|
||||
{
|
||||
this.savePath = savePath;
|
||||
Directory.CreateDirectory(savePath);
|
||||
preferenceList = new Dictionary<Type, Preferences>();
|
||||
preferenceList = new Dictionary<Type, object>();
|
||||
Debug.WriteLine("Preference manager setting up...");
|
||||
Type[] preferenceTypes = new Type[preferences.Length];
|
||||
for (int prefID = 0; prefID < preferences.Length; prefID++)
|
||||
@@ -26,10 +26,10 @@ namespace RecrownedAthenaeum.Persistence
|
||||
Debug.WriteLine(preferences[prefID] + " added to list of preferences");
|
||||
}
|
||||
|
||||
xmlSerializer = new XmlSerializer(typeof(Preferences), preferenceTypes);
|
||||
xmlSerializer = new XmlSerializer(typeof(object), preferenceTypes);
|
||||
}
|
||||
|
||||
public T GetPreferences<T>() where T : Preferences
|
||||
public T GetPreferences<T>()
|
||||
{
|
||||
return (T)preferenceList[typeof(T)];
|
||||
}
|
||||
@@ -49,7 +49,7 @@ namespace RecrownedAthenaeum.Persistence
|
||||
|
||||
public void Save()
|
||||
{
|
||||
foreach (KeyValuePair<Type, Preferences> prefs in preferenceList)
|
||||
foreach (KeyValuePair<Type, object> prefs in preferenceList)
|
||||
{
|
||||
SaveSpecific(prefs.Key);
|
||||
}
|
||||
@@ -61,7 +61,7 @@ namespace RecrownedAthenaeum.Persistence
|
||||
if (File.Exists(path))
|
||||
{
|
||||
Stream stream = new FileStream(path, FileMode.Open);
|
||||
preferenceList[preference] = (Preferences)xmlSerializer.Deserialize(stream);
|
||||
preferenceList[preference] = xmlSerializer.Deserialize(stream);
|
||||
stream.Close();
|
||||
return true;
|
||||
}
|
||||
|
Reference in New Issue
Block a user