Beispiel #1
0
        public T Get(IReadOnlyStorage storage)
        {
            if (storage == null)
            {
                throw new ArgumentNullException(nameof(storage));
            }
            if (_valid)
            {
                return(_value);
            }

            _value = ReadValueFrom(storage);
            _valid = true;

            return(_value);
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
 protected abstract T ReadValueFrom(IReadOnlyStorage storage);
Beispiel #4
0
 /// <inheritdoc />
 protected override float ReadValueFrom(IReadOnlyStorage storage) => storage.GetFloat(Name, DefaultValue);
Beispiel #5
0
 /// <inheritdoc />
 protected override string ReadValueFrom(IReadOnlyStorage storage) => storage.GetString(Name, DefaultValue);
Beispiel #6
0
		protected override DateTime ReadValueFrom(IReadOnlyStorage storage) => storage.GetDateTime(Name, DefaultValue);
Beispiel #7
0
 /// <inheritdoc />
 protected override bool ReadValueFrom(IReadOnlyStorage storage) => storage.GetBool(Name, DefaultValue);
Beispiel #8
0
 /// <inheritdoc />
 protected override int ReadValueFrom(IReadOnlyStorage storage) => storage.GetInt(Name, DefaultValue);