DevToys.PocoCsv.Core 1.4.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package DevToys.PocoCsv.Core --version 1.4.1
NuGet\Install-Package DevToys.PocoCsv.Core -Version 1.4.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DevToys.PocoCsv.Core" Version="1.4.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DevToys.PocoCsv.Core --version 1.4.1
#r "nuget: DevToys.PocoCsv.Core, 1.4.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install DevToys.PocoCsv.Core as a Cake Addin
#addin nuget:?package=DevToys.PocoCsv.Core&version=1.4.1

// Install DevToys.PocoCsv.Core as a Cake Tool
#tool nuget:?package=DevToys.PocoCsv.Core&version=1.4.1

DevToys.PocoCsv.Core

DevToys.PocoCsv.Core is a class library to read and write to Csv fast. It contains CsvStreamReader, CsvStreamWriter and Serialization classes CsvReader<T> and CsvWriter<T>.

  • Read/write serialize/deserialize data to and from Csv fast.
  • Use Linq to query large CSV files with CsvReader<T>.ReadAsEnumerable().
  • Use CsvWriter<T>.Write() to write large data tables to Csv.
  • Retrieve schema for a csv file with CsvUtils.GetCsvSchema() which can be used to create a poco object.

Three flavors for reading and writing CSV files:

  1. Stream
  2. <T> Serialize / Deserialize to T
  3. dynamic. Use dynamic to Read or Write CSV, this is slightly slower then <T>

CsvStreamReader

    string file = "C:\Temp\data.csv";
    using (CsvStreamReader _reader = new CsvStreamReader(file))
    {
        _reader.Separator = ',';
        while (!_reader.EndOfCsvStream)
        {
            List<string> _values = _reader.ReadCsvLine().ToList();
        }
    }

CsvStreamWriter

    string file = @"D:\Temp\test.csv";
    using (CsvStreamWriter _writer = new CsvStreamWriter(file))
    {
        var _line = new string[] { "Row 1", "Row A,A", "Row 3", "Row B" };
        _writer.WriteCsvLine(_line);
    }

CsvReader<T>

    public class Data
    {
        [Column(Index = 0)]
        public string Column1 { get; set; }

        [Column(Index = 1)]
        public string Column2 { get; set; }

        [Column(Index = 2)]
        public string Column3 { get; set; }

        [Column(Index = 5)]
        public string Column5 { get; set; }
    }
    
    string file = @"D:\Temp\data.csv");

    using (CsvReader<Data> _reader = new(file))
    {        
        _reader.Open();
        _reader.Separator = ','; // or use _reader.DetectSeparator(); 
        var _data = Reader.ReadAsEnumerable().Where(p => p.Column1.Contains("16"));
        var _materialized = _data.ToList();

    }    
  • Reader.ReadAsEnumerable() reads and deserializes each csv file line per iteration in the collection, this allows for querying mega sized files.
  • CsvReader and CsvWriter can deserialize / serialize to simple types, this includes enum and byte[].
  • use CsvReader.DetectSeparator() to auto set the separator (looks for commonly used separators in first 10 lines).

CsvWriter<T>

    private IEnumerable<CsvSimple> LargeData()
    {
        for (int ii = 0; ii < 10000000; ii++)
        {
            CsvSimple _line = new()
            {
                AfBij = "bij",
                Bedrag = "100",
                Code = "test",
                Datum = "20200203",
                Mededelingen = $"test {ii}",
                Rekening = "3434",
                Tegenrekening = "3423424"
            };
            yield return _line;
        }
    }
    
    
    string file = @"D:\largedata.csv";
    using (CsvWriter<CsvSimple> _writer = new(file) { Separator = ',', Append = true })
    {
        _writer.Open();
        _writer.Write(LargeData());
    }
      

CsvReaderDynamic

    string file = @"C:\Temp\data.csv";
    using (CsvReaderDynamic _reader = new(file))
    {
        _reader.FirstRowIsHeader = true;
        _reader.Open();
        foreach (dynamic row in _reader.ReadAsEnumerable())
        {
            ...
        }
    }

CsvWriterDynamic

    string file = @"C:temp\data.csv");

    using (CsvWriterDynamic _writer = new(file))
    {
        dynamic row = new ExpandoObject();
        row.Id = 124;
        row.Name = "Name";

        List<dynamic> _data = new List<dynamic>();
        _data.Add(row);

        _writer.Write(_data);
    }
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
4.2.2 117 2/28/2024
4.2.1 89 2/24/2024
4.2.0 97 2/23/2024
4.1.2 92 2/22/2024
4.1.1 94 2/21/2024
4.1.0 100 2/21/2024
4.0.1 114 2/12/2024
4.0.0 97 2/12/2024
3.1.13 92 2/8/2024
3.1.12 105 2/7/2024
3.1.11 77 1/31/2024
3.1.10 87 1/19/2024
3.1.9 95 1/13/2024
3.1.8 90 1/12/2024
3.1.7 83 1/11/2024
3.1.5 102 1/8/2024
3.1.3 153 12/1/2023
3.1.2 101 12/1/2023
3.1.0 104 11/28/2023
3.0.7 185 8/27/2023
3.0.6 127 8/23/2023
3.0.5 138 8/23/2023
3.0.4 153 8/17/2023
3.0.3 150 8/15/2023
3.0.2 155 8/11/2023
3.0.1 164 8/11/2023
3.0.0 151 8/11/2023
2.0.7 195 8/9/2023
2.0.5 166 8/4/2023
2.0.4 149 8/3/2023
2.0.3 140 7/31/2023
2.0.2 149 7/28/2023
2.0.0 154 7/19/2023
1.7.53 194 4/14/2023
1.7.52 182 4/12/2023
1.7.51 169 4/7/2023
1.7.43 202 4/3/2023
1.7.42 182 4/3/2023
1.7.41 174 4/3/2023
1.7.5 193 4/7/2023
1.7.3 211 4/3/2023
1.7.2 207 4/3/2023
1.7.1 190 4/3/2023
1.7.0 204 4/1/2023
1.6.3 218 3/31/2023
1.6.2 207 3/29/2023
1.6.1 198 3/29/2023
1.6.0 206 3/27/2023
1.5.8 218 3/24/2023
1.5.7 184 3/22/2023
1.5.6 200 3/22/2023
1.5.5 212 3/21/2023
1.5.4 225 3/21/2023
1.5.1 214 3/20/2023
1.5.0 217 3/19/2023
1.4.5 209 3/18/2023
1.4.4 249 3/18/2023
1.4.3 206 3/18/2023
1.4.2 238 3/18/2023
1.4.1 204 3/18/2023
1.4.0 205 3/18/2023
1.3.92 213 3/18/2023
1.3.91 219 3/17/2023
1.3.9 226 3/17/2023
1.3.8 198 3/17/2023
1.3.7 213 3/17/2023
1.3.6 195 3/17/2023
1.3.5 214 3/17/2023
1.3.4 226 3/17/2023
1.3.3 214 3/16/2023
1.3.2 194 3/16/2023
1.3.1 227 3/16/2023
1.3.0 190 3/16/2023
1.2.0 213 3/14/2023
1.1.6 255 2/24/2023
1.1.5 289 2/16/2023
1.1.4 450 5/18/2022
1.1.3 694 1/27/2022
1.1.2 627 1/27/2022
1.1.1 676 1/14/2022
1.1.0 5,814 11/23/2021
1.0.5 370 5/11/2021
1.0.4 315 4/14/2021
1.0.3 316 4/12/2021
1.0.2 313 4/12/2021
1.0.1 309 4/7/2021
1.0.0 367 4/7/2021