Skip to content

Instantly share code, notes, and snippets.

@joshgo
Last active December 15, 2015 04:59
Show Gist options
  • Save joshgo/5205773 to your computer and use it in GitHub Desktop.
Save joshgo/5205773 to your computer and use it in GitHub Desktop.
CsvHelper - ICsvParser implementation using Lumenworks Lumenworks is a very efficient and very reliable CsvParser.
public class LumenICsvPaser : CsvHelper.ICsvParser
{
private LumenWorks.Framework.IO.Csv.CsvReader _reader = null;
public LumenICsvPaser(System.IO.TextReader stream) : this(stream, new CsvConfiguration())
{
}
public LumenICsvPaser(System.IO.TextReader stream, CsvConfiguration config)
{
_reader = new LumenWorks.Framework.IO.Csv.CsvReader(stream, false, config.Delimiter[0], config.BufferSize);
Configuration = config;
}
public void Dispose()
{
if (_reader != null)
{
_reader.Dispose();
_reader = null;
}
}
public CsvConfiguration Configuration { get; private set; }
public int FieldCount { get { return _reader.FieldCount; } }
public long CharPosition { get { throw new NotImplementedException(); } }
public long BytePosition { get { throw new NotImplementedException(); } }
public int Row { get { return (int) _reader.CurrentRecordIndex; } }
public string RawRecord { get { return _reader.GetCurrentRawData(); } }
public string[] Read()
{
if(!_reader.ReadNextRecord())
return null;
string[] buffer = new string[FieldCount];
_reader.CopyCurrentRecordTo(buffer);
return buffer;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment