Class CsvParser
CSV reader. Reads a comma (or other char) delimited file, line by line and parses each line to a new object. Header lines can be handled with the HeaderParser.
public class CsvParser : IDisposable
- Inheritance
-
CsvParser
- Implements
- Derived
- Inherited Members
- Extension Methods
Constructors
CsvParser(string, char, Func<string[], CsvParser, Dictionary<string, string>, object>, Func<string, CsvParser, bool>)
protected CsvParser(string filePath, char delimiter = ',', Func<string[], CsvParser, Dictionary<string, string>, object> rowParser = null, Func<string, CsvParser, bool> headerParser = null)
Parameters
filePathstringdelimitercharrowParserFunc<string[], CsvParser, Dictionary<string, string>, object>headerParserFunc<string, CsvParser, bool>
Fields
Header
Last header row read by the header parser.
protected string Header
Field Value
HeaderData
protected Dictionary<string, string> HeaderData
Field Value
HeaderParser
Returns a boolean representing wether the current line is a Header.
protected Func<string, CsvParser, bool> HeaderParser
Field Value
RowParser
Parses a split line to a new object. Applied on every line not a header.
protected Func<string[], CsvParser, Dictionary<string, string>, object> RowParser
Field Value
Stream
public StreamReader Stream
Field Value
Properties
CanPeek
public bool CanPeek { get; }
Property Value
Delimiter
public char Delimiter { get; }
Property Value
FilePath
public string FilePath { get; }
Property Value
IsDone
public bool IsDone { get; }
Property Value
Methods
AfterParse<T>(List<T>)
protected virtual List<T> AfterParse<T>(List<T> parsed)
Parameters
parsedList<T>
Returns
- List<T>
Type Parameters
T
BeforeParse(Type)
protected virtual void BeforeParse(Type type)
Parameters
typeType
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources
public void Dispose()
ParseAll<T>(bool, bool)
public List<T> ParseAll<T>(bool skipNull = true, bool breakOnNull = false)
Parameters
Returns
- List<T>
Type Parameters
T
ParseRow<T>()
protected T ParseRow<T>()
Returns
- T
Type Parameters
T
PeekLine()
Returns the next line to be read without consuming it, thus it will still be read by ReadLine.
protected string PeekLine()
Returns
PeekNextLine()
Returns the next line that has not already been peeked. The line will not be consumed but still will be read by ReadLine.
protected string PeekNextLine()
Returns
ReadRow()
protected string[] ReadRow()
Returns
- string[]