public bool DeleteValue(string key, bool roaming = false) { if (string.IsNullOrEmpty(key)) { throw new ArgumentException("Key must have a value", "key"); } SharedPreferencesEditor.Remove(key); return(SharedPreferencesEditor.Commit()); }
public bool ClearAllValues(bool roaming = false) { SharedPreferencesEditor.Clear(); return(SharedPreferencesEditor.Commit()); }
public bool AddOrUpdateValue <T>(string key, T value = default(T), bool roaming = false) { lock (locker) { Type typeOf = value.GetType(); if (typeOf.IsGenericType && typeOf.GetGenericTypeDefinition() == typeof(Nullable <>)) { typeOf = Nullable.GetUnderlyingType(typeOf); } var typeCode = Type.GetTypeCode(typeOf); switch (typeCode) { case TypeCode.Decimal: SharedPreferencesEditor.PutLong(key, (long)Convert.ToDecimal(value, CultureInfo.InvariantCulture)); break; case TypeCode.Boolean: SharedPreferencesEditor.PutBoolean(key, Convert.ToBoolean(value)); break; case TypeCode.Int64: SharedPreferencesEditor.PutLong(key, (long)Convert.ToInt64(value, CultureInfo.InvariantCulture)); break; case TypeCode.String: SharedPreferencesEditor.PutString(key, Convert.ToString(value)); break; case TypeCode.Double: SharedPreferencesEditor.PutLong(key, (long)Convert.ToDouble(value, CultureInfo.InvariantCulture)); break; case TypeCode.Int32: SharedPreferencesEditor.PutInt(key, Convert.ToInt32(value, CultureInfo.InvariantCulture)); break; case TypeCode.Single: SharedPreferencesEditor.PutFloat(key, Convert.ToSingle(value, CultureInfo.InvariantCulture)); break; case TypeCode.DateTime: SharedPreferencesEditor.PutLong(key, ((DateTime)(object)value).Ticks); break; default: throw new ArgumentException(string.Format("Value of type {0} is not supported.", value.GetType().Name)); } } lock (locker) { SharedPreferencesEditor.Commit(); } return(true); }