Exemplo n.º 1
0
        public CsvReader(TextReader reader, CsvReaderOptions options)
        {
            _lineReader = new LineReader(options, reader);

            _cursor = _lineReader.GetLines().GetEnumerator();

            // Read the first line, as we expect it to have headers
            _cursor.MoveNext();

            // The file format here is that the first row includes the
            // columnHeaders in the format "<name>:<type>"
            var columnHeaders = _cursor.Current;

            var columns = new DbColumn[columnHeaders.Length];

            for (var i = 0; i < columnHeaders.Length; i++) {
                // Unquote headers
                var header = columnHeaders[i].Replace("\"", "");
                var splitHeader = header.Split(':');

                if (splitHeader.Length == 2) {
                    var columnName = splitHeader[0];
                    var typeHeader = splitHeader[1];

                    var mungType = MungType.Parse(typeHeader);

                    columns[i] = new DbColumn(columnName, mungType);
                } else {
                    columns[i] = new DbColumn(header, MungType.Get(MungTypeCode.String));

                }
            }
            _columns = columns.ToList();
        }
Exemplo n.º 2
0
 public LineReader(CsvReaderOptions options, FileInfo file, Encoding encoding)
 {
     _opts = options;
     var input = file.Open(FileMode.Open, FileAccess.Read, FileShare.Read);
     _dispose = true;
     _reader = new StreamReader(input, encoding);
 }
Exemplo n.º 3
0
 public LineReader(CsvReaderOptions options, Stream input, Encoding encoding, bool dispose = false)
 {
     _opts = options;
     this._dispose = dispose;
     this._reader = new StreamReader(input, encoding);
 }
Exemplo n.º 4
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="input">The stream to read</param>
 /// <param name="dispose"></param>
 public LineReader(CsvReaderOptions options, TextReader reader, bool dispose = false)
 {
     _opts = options;
     this._reader = reader;
     this._dispose = dispose;
 }