Inventory logger
This commit is contained in:
parent
29fba4b7cb
commit
de2057789a
41 changed files with 12834 additions and 171 deletions
59
Shared/Settings/Setting.cs
Normal file
59
Shared/Settings/Setting.cs
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
using System;
|
||||
|
||||
namespace Mag.Shared.Settings
|
||||
{
|
||||
class Setting<T>
|
||||
{
|
||||
public readonly string Xpath;
|
||||
|
||||
public readonly string Description;
|
||||
|
||||
public readonly T DefaultValue;
|
||||
|
||||
private T value;
|
||||
public T Value
|
||||
{
|
||||
get
|
||||
{
|
||||
return value;
|
||||
}
|
||||
set
|
||||
{
|
||||
// If we're setting it to the value its already at, don't continue with the set.
|
||||
if (Object.Equals(this.value, value))
|
||||
return;
|
||||
|
||||
// The value differs, set it.
|
||||
this.value = value;
|
||||
|
||||
StoreValueInConfigFile();
|
||||
|
||||
if (Changed != null)
|
||||
Changed(this);
|
||||
}
|
||||
}
|
||||
|
||||
public event Action<Setting<T>> Changed;
|
||||
|
||||
public Setting(string xpath, string description = null, T defaultValue = default(T))
|
||||
{
|
||||
Xpath = xpath;
|
||||
|
||||
Description = description;
|
||||
|
||||
DefaultValue = defaultValue;
|
||||
|
||||
LoadValueFromConfig(defaultValue);
|
||||
}
|
||||
|
||||
void LoadValueFromConfig(T defaultValue)
|
||||
{
|
||||
value = SettingsFile.GetSetting(Xpath, defaultValue);
|
||||
}
|
||||
|
||||
void StoreValueInConfigFile()
|
||||
{
|
||||
SettingsFile.PutSetting(Xpath, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue