public object Get(Setting appSetting) { SettingsHive hive; SettingsHive?nullable; object obj2; object obj3; Validate.IsNotNull <Setting>(appSetting, "appSetting"); SettingConverter converter = appSetting.Converter; if (!converter.IsValidValueType(appSetting.ValueType)) { throw new ArgumentException("appSetting.ValueType is not a supported Type"); } GetHiveQueryOrder(appSetting.Scope, out hive, out nullable); if (this.TryGetValue(hive, appSetting.Path, appSetting.ValueType, converter, out obj2)) { return(obj2); } if (nullable.HasValue && this.TryGetValue(nullable.Value, appSetting.Path, appSetting.ValueType, converter, out obj3)) { return(obj3); } return(appSetting.DefaultValue); }
public Setting(string path, SettingScope scope, TValue defaultValue, SettingConverter converter) : base(path, scope, typeof(TValue), converter) { if (Setting <TValue> .boxPolicy == null) { Setting <TValue> .boxPolicy = this.OnGetStaticBoxPolicy(); } if (Setting <TValue> .equalityComparer == null) { Setting <TValue> .equalityComparer = this.OnGetStaticEqualityComparer(); } base.Initialize(this.BoxValue(defaultValue)); }
internal Setting(string path, SettingScope scope, Type valueType, SettingConverter converter) { Validate.Begin().IsNotNullOrWhiteSpace(path, "path").IsNotNull <Type>(valueType, "valueType").IsNotNull <SettingConverter>(converter, "converter").Check(); if (!converter.IsValidValueType(valueType)) { throw new ArgumentException("valueType is not a supported Type"); } this.path = path; this.scope = scope; this.valueType = valueType; this.converter = converter; }
public bool TrySet(Setting appSetting, object value) { SettingsHive hive; SettingsHive?nullable; Validate.IsNotNull <Setting>(appSetting, "appSetting"); SettingConverter converter = appSetting.Converter; if (!converter.IsValidValueType(appSetting.ValueType)) { throw new ArgumentException("appSetting.ValueType is not a supported Type"); } if (!converter.IsValidValue(appSetting.ValueType, value)) { throw new ArgumentException("value is not suitable for appSetting"); } GetHiveQueryOrder(appSetting.Scope, out hive, out nullable); bool flag = this.OnQueryCanSetSystemWideValue(); string str = converter.ConvertToStorage(appSetting.ValueType, value); bool flag2 = false; if (!flag2) { if ((hive == SettingsHive.SystemWide) && !flag) { flag2 = false; } else { flag2 = this.UnsafeTrySet(hive, appSetting.Path, str); } } if (flag2 || !nullable.HasValue) { return(flag2); } if ((((SettingsHive)nullable.Value) == SettingsHive.SystemWide) && !flag) { return(false); } return(this.UnsafeTrySet(nullable.Value, appSetting.Path, str)); }
private bool TryGetValue(SettingsHive hive, string path, Type valueType, SettingConverter converter, out object value) { string str; if (!this.TryGet(hive, path, out str)) { value = null; return(false); } try { value = converter.ConvertFromStorage(valueType, str); return(true); } catch (Exception) { value = null; return(false); } }
protected StaticListChoiceSetting(string path, SettingScope scope, T defaultValue, IEqualityComparer <T> equalityComparer, SettingConverter converter) : base(path, scope, defaultValue, converter) { Validate.IsNotNull <IEqualityComparer <T> >(equalityComparer, "equalityComparer"); this.equalityComparer = equalityComparer; this.InvalidateValueChoices(); }
protected StaticListChoiceSetting(string path, SettingScope scope, T defaultValue, SettingConverter converter) : this(path, scope, defaultValue, EqualityComparer <T> .Default, converter) { }
protected ScalarSetting(string path, SettingScope scope, TValue defaultValue, TValue minValue, TValue maxValue, SettingConverter <TValue> converter) : base(path, scope, defaultValue, converter) { if (minValue.IsGreaterThan <TValue>(maxValue) || maxValue.IsLessThan <TValue>(minValue)) { throw new ArgumentException("minValue must be less than or equal to maxValue"); } this.minValue = minValue; this.maxValue = maxValue; }