Skip to content

Instantly share code, notes, and snippets.

@mburtscher
Created August 13, 2014 06:43
Show Gist options
  • Save mburtscher/723c2f3e26e8ee47a0c1 to your computer and use it in GitHub Desktop.
Save mburtscher/723c2f3e26e8ee47a0c1 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using PropertyChanged;
namespace Fody
{
[ImplementPropertyChanged]
class Misbehavior
{
/// <summary>
/// Holds all settings as key/value store.
/// </summary>
private Dictionary<string, object> values = new Dictionary<string, object>();
/// <summary>
/// The default setting for A, may be set using SetDefaultA()
/// </summary>
private int settingADefault = 1337;
/// <summary>
/// Get/set setting A.
/// </summary>
public int A
{
get { return GetValue<int>("a", settingADefault); }
set { SetValue("a", value); }
}
/// <summary>
/// Gets value from key/value store or return default.
/// </summary>
private T GetValue<T>(string key, T defaultValue)
{
object value;
if(values.TryGetValue(key, out value))
{
return (T)value;
}
else
{
return defaultValue;
}
}
/// <summary>
/// Sets value in key/value store.
/// </summary>
private void SetValue(string key, object value)
{
values[key] = value;
}
/// <summary>
/// Sets the default for setting A.
/// </summary>
/// <param name="value"></param>
public void SetDefaultA(int value)
{
settingADefault = value;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment