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