/// <summary> /// Constructor that will deal with streams. /// </summary> /// <param name="stream">The stream the csv data exists in.</param> /// <param name="options">The stream options we need to use for parsing.</param> public CsvStreamReader(Stream stream, CsvStreamOptions options) { _options = options; _stream = stream; _rowReader = new RowReader(new CharReader(_stream), _options.RowDelimiter, _options.Wrapper); _headerReader = new RowReader(new CharReader(_stream), _options.HeaderRowDelimiter, _options.Wrapper); }
public void TestRowSeperator() { var options = new CsvStreamOptions() { HeaderRowDelimiter = "\r\n", RowDelimiter = "\r\n" }; using (var reader = new CsvDictionaryStreamReader("./test2.csv", options)) { var result = reader.AsEnumerable().ToList(); Assert.AreEqual(result.Count, 39); } }
public void TestSaveFile() { var total = 25; var options = new CsvStreamOptions() { Delimiter = ":", RowDelimiter = "|||", Wrapper = '\'', HeaderRowDelimiter = "|||", HeaderDelimiter = ":" }; var list = new List <TestModel>(); for (var i = 0; i < total; ++i) { list.Add(new TestModel() { Name = $"Test {i}", Type = TestType.Attachment, Cost = 10 * i, Id = i, Date = DateTime.Now }); } CsvParser.SaveFile("test.writer.csv", list, options); // Parse the respones and check if it was saved correctly. var entries = CsvParser.ParseFile <TestModel>("test.writer.csv", options).ToList(); Assert.AreEqual(entries.Count(), total); for (var i = 0; i < entries.Count; ++i) { Assert.AreEqual(entries[i].Name, list[i].Name); Assert.AreEqual(entries[i].Type, list[i].Type); Assert.AreEqual(entries[i].Cost, list[i].Cost); Assert.AreEqual(entries[i].Id, list[i].Id); Assert.AreEqual(entries[i].Date.ToString(), list[i].Date.ToString()); } }
/// <summary> /// Constructor that will deal with streams. /// </summary> /// <param name="stream">The stream the csv data exists in.</param> /// <param name="options">The stream options we need to use for parsing.</param> public CsvDictionaryStreamReader(Stream stream, CsvStreamOptions options) : base(stream, options) { }
/// <summary> /// Constructor that will deal with files and convert them into a stream. /// </summary> /// <param name="path">The file path that we need to create a stream from.</param> /// <param name="options">The stream options we need to use for parsing.</param> public CsvDictionaryStreamReader(string path, CsvStreamOptions options) : base(path, options) { }
/// <summary> /// Constructor that will deal with streams. /// </summary> /// <param name="stream">The stream the csv data exists in.</param> /// <param name="options">The stream options we need to use for parsing.</param> public CsvRowStreamReader(Stream stream, CsvStreamOptions options) : base(stream, options) { }
/// <summary> /// Constructor that will deal with files and convert them into a stream. /// </summary> /// <param name="path">The file path that we need to create a stream from.</param> /// <param name="options">The stream options we need to use for parsing.</param> public CsvRowStreamReader(string path, CsvStreamOptions options) : base(path, options) { }
/// <summary> /// Constructor that will deal with files and convert them into a stream. /// </summary> /// <param name="path">The file path that we need to create a stream from.</param> /// <param name="options">The stream options we need to use for parsing.</param> public CsvStreamReader(string path, CsvStreamOptions options) : this(File.Open(path, FileMode.Open, FileAccess.Read), options) { }