private void ApplyValue(object instance, object value) { if (Type == typeof(decimal)) { if (value is string str) { str = str.Replace(',', '.').RemoveSpaces().ReplaceWhiteSpaces().Trim(); if (str.IsEmpty()) { return; } value = str; } } else if (Type == typeof(DateTimeOffset)) { if (value is string str) { if (_dateParser == null) { _dateParser = new FastDateTimeParser(Format); } var dto = _dateParser.ParseDto(str); if (dto.Offset.IsDefault()) { var tz = Scope <TimeZoneInfo> .Current?.Value; if (tz != null) { dto = dto.UtcDateTime.ApplyTimeZone(tz); } } value = dto; } } else if (Type == typeof(TimeSpan)) { if (value is string str) { if (_timeParser == null) { _timeParser = new FastTimeSpanParser(Format); } value = _timeParser.Parse(str); } } if (value != null) { OnApply(instance, value.To(Type)); } }
/// <summary> /// Reset state. /// </summary> public void Reset() { _dateParser = null; _timeParser = null; }