Esempio n. 1
0
        private IEnumerable <ICsvRow> where_clause <T>(string name, T value, Func <string, T, bool> match)
        {
            int columnIndex = CsvHelpers.NameToColumnIndex(_columns, name);

            foreach (var line in File.ReadLines(_path))
            {
                if (IsNullOrWhiteSpace(line))
                {
                    continue;
                }

                var field = CsvHelpers.ParseField(line, columnIndex);

                if (IsNullOrWhiteSpace(field))
                {
                    continue;
                }

                if (!match(field, value))
                {
                    continue;
                }

                yield return
                    (CsvRow.New(_columns, line));
            }
        }
Esempio n. 2
0
        private CsvParser(string path, CsvConfig config)
        {
            var firstLine = CsvHelpers.ReadFirstNotBlankLine(path);    // will throw IoException if file does not exist

            _path    = path;
            _isEmpty = firstLine == null;

            var header = config.Header ?? firstLine;

            _columns = CsvHelpers.ParseHeader(_path, header);
        }
Esempio n. 3
0
        string ICsvRow.this[string name]
        {
            get
            {
                int index = CsvHelpers.NameToColumnIndex(_columns, name);

                if (index >= _fields.Length)
                {
                    return(null);
                }

                return(_fields[index]);
            }
        }