public static void WriteSetting <T>(string propertyName, T propertyValue) { switch (Type.GetTypeCode(typeof(T))) { case TypeCode.String: _userSettingsStore.SetString(CollectionName, propertyName, Convert.ToString(propertyValue)); break; case TypeCode.Boolean: _userSettingsStore.SetBoolean(CollectionName, propertyName, Convert.ToBoolean(propertyValue)); break; case TypeCode.Int32: _userSettingsStore.SetInt32(CollectionName, propertyName, Convert.ToInt32(propertyValue)); break; case TypeCode.Int64: _userSettingsStore.SetInt64(CollectionName, propertyName, Convert.ToInt64(propertyValue)); break; case TypeCode.UInt32: _userSettingsStore.SetUInt32(CollectionName, propertyName, Convert.ToUInt32(propertyValue)); break; case TypeCode.UInt64: _userSettingsStore.SetUInt64(CollectionName, propertyName, Convert.ToUInt64(propertyValue)); break; default: _userSettingsStore.SetString(CollectionName, propertyName, Convert.ToString(propertyValue)); break; } }
public void Write(string subPath, string property, object value) { Validate.IsNotNull(property, nameof(property)); Validate.IsNotEmpty(property, nameof(property)); var collection = subPath != null?Path.Combine(_root, subPath) : _root; _store.CreateCollection(collection); if (value is bool b) { _store.SetBoolean(collection, property, b); } else if (value is int i) { _store.SetInt32(collection, property, i); } else if (value is uint u) { _store.SetUInt32(collection, property, u); } else if (value is long l) { _store.SetInt64(collection, property, l); } else if (value is ulong ul) { _store.SetUInt64(collection, property, ul); } else { _store.SetString(collection, property, value?.ToString() ?? ""); } }
public void Write(string subpath, string property, object value) { Guard.ArgumentNotNull(property, nameof(property)); Guard.ArgumentNotEmptyString(property, nameof(property)); var collection = subpath != null?Path.Combine(root, subpath) : root; store.CreateCollection(collection); if (value is bool) { store.SetBoolean(collection, property, (bool)value); } else if (value is int) { store.SetInt32(collection, property, (int)value); } else if (value is uint) { store.SetUInt32(collection, property, (uint)value); } else if (value is long) { store.SetInt64(collection, property, (long)value); } else if (value is ulong) { store.SetUInt64(collection, property, (ulong)value); } else { store.SetString(collection, property, value?.ToString() ?? ""); } }