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); }
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)); }