/// <summary> /// Reads a field, as a list of decimals. /// </summary> /// <param name="key">The column</param> /// <returns>The value</returns> /// <exception cref="InvalidCastException"></exception> public IReadOnlyList <decimal> GetDecimalList(string key) { string value = GetValue(key); if (string.IsNullOrEmpty(value)) { return(null); } string[] parts = GetList(value); List <decimal> res = new List <decimal>(parts.Length); foreach (string part in parts) { decimal entry; if (CsvValueParser.TryParseDecimal(part, out entry)) { res.Add(entry); } else { throw new InvalidCastException( ); } } return(res); }
/// <summary> /// Reads a field, as a list of integers. /// </summary> /// <param name="key">The column</param> /// <returns>The value</returns> /// <exception cref="InvalidCastException"></exception> public IReadOnlyList <int> GetIntList(string key) { string value = GetCellText(key); if (string.IsNullOrEmpty(value)) { return(null); } string[] parts = GetList(value); List <int> res = new List <int>(parts.Length); foreach (string part in parts) { int entry; if (CsvValueParser.TryParseInt(part, out entry)) { res.Add(entry); } else { throw new InvalidCastException(); } } return(res); }
/// <summary> /// Reads a field, as a boolean. /// </summary> /// <param name="key">The column</param> /// <returns>The value</returns> /// <exception cref="InvalidCastException"></exception> public bool?GetBoolean(string key) { string value = GetValue(key); if (string.IsNullOrEmpty(value)) { return(false); // treat null as false } bool result; if (!CsvValueParser.TryParseBool(value, out result)) { throw new InvalidCastException( ); } return(result); }
/// <summary> /// Reads a field, as a date-time. /// </summary> /// <param name="key">The column</param> /// <returns>The value</returns> /// <exception cref="InvalidCastException"></exception> public DateTime?GetDateTime(string key) { string value = GetValue(key); if (string.IsNullOrEmpty(value)) { return(null); } DateTime result; if (!CsvValueParser.TryParseDateTime(value, _settings.TimeZoneInfo, out result)) { throw new InvalidCastException( ); } return(result); }
/// <summary> /// Reads a field, as a decimal. /// </summary> /// <param name="key">The column</param> /// <returns>The value</returns> /// <exception cref="InvalidCastException"></exception> public decimal?GetDecimal(string key) { string value = GetValue(key); if (string.IsNullOrEmpty(value)) { return(null); } decimal result; if (!CsvValueParser.TryParseDecimal(value, out result)) { throw new InvalidCastException( ); } return(result); }
/// <summary> /// Reads a field, as an integer. /// </summary> /// <param name="key">The column</param> /// <returns>The value</returns> /// <exception cref="InvalidCastException"></exception> public int?GetInt(string key) { string value = GetValue(key); if (string.IsNullOrEmpty(value)) { return(null); } int result; if (!CsvValueParser.TryParseInt(value, out result)) { throw new InvalidCastException( ); } return(result); }