public T Get(IReadOnlyStorage storage) { if (storage == null) { throw new ArgumentNullException(nameof(storage)); } if (_valid) { return(_value); } _value = ReadValueFrom(storage); _valid = true; return(_value); }
public static DateTime GetDateTime(this IReadOnlyStorage storage, string key, DateTime defaultValue = default) { if (storage == null) { throw new ArgumentNullException(nameof(storage)); } if (key == null) { throw new ArgumentNullException(nameof(key)); } var storedString = storage.GetString(key, null); if (storedString == null) { return(defaultValue); } return(DateTime.TryParse(storedString, DefaultFormatProvider, DateTimeStyles.None, out var dateTime) ? dateTime : defaultValue); }
protected abstract T ReadValueFrom(IReadOnlyStorage storage);
/// <inheritdoc /> protected override float ReadValueFrom(IReadOnlyStorage storage) => storage.GetFloat(Name, DefaultValue);
/// <inheritdoc /> protected override string ReadValueFrom(IReadOnlyStorage storage) => storage.GetString(Name, DefaultValue);
protected override DateTime ReadValueFrom(IReadOnlyStorage storage) => storage.GetDateTime(Name, DefaultValue);
/// <inheritdoc /> protected override bool ReadValueFrom(IReadOnlyStorage storage) => storage.GetBool(Name, DefaultValue);
/// <inheritdoc /> protected override int ReadValueFrom(IReadOnlyStorage storage) => storage.GetInt(Name, DefaultValue);