Ejemplo n.º 1
0
        /// <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 = GetValue(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);
        }
Ejemplo n.º 2
0
        /// <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);
        }