{"id":25199400,"url":"https://github.com/nuskey8/Csv-CSharp","last_synced_at":"2025-10-25T01:30:41.366Z","repository":{"id":245065299,"uuid":"816721922","full_name":"yn01dev/Csv-CSharp","owner":"yn01dev","description":"Fast CSV Serializer for .NET and Unity","archived":false,"fork":false,"pushed_at":"2024-11-05T02:28:21.000Z","size":207,"stargazers_count":67,"open_issues_count":1,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-08T17:36:13.648Z","etag":null,"topics":["csv","csv-parser","serializer"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yn01dev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-06-18T09:27:19.000Z","updated_at":"2025-02-02T06:35:06.000Z","dependencies_parsed_at":"2024-06-22T15:44:18.415Z","dependency_job_id":"f9a142d0-cbc0-44f0-8ea5-a008c86d2355","html_url":"https://github.com/yn01dev/Csv-CSharp","commit_stats":null,"previous_names":["annulusgames/csv-csharp","yn01dev/csv-csharp"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yn01dev%2FCsv-CSharp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yn01dev%2FCsv-CSharp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yn01dev%2FCsv-CSharp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yn01dev%2FCsv-CSharp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yn01dev","download_url":"https://codeload.github.com/yn01dev/Csv-CSharp/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238053508,"owners_count":19408702,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csv","csv-parser","serializer"],"created_at":"2025-02-10T04:01:36.409Z","updated_at":"2025-10-25T01:30:41.360Z","avatar_url":"https://github.com/yn01dev.png","language":"C#","readme":"# Csv-CSharp\n\n[![NuGet](https://img.shields.io/nuget/v/CsvCSharp.svg)](https://www.nuget.org/packages/CsvCSharp)\n[![Releases](https://img.shields.io/github/release/nuskey8/Csv-CSharp.svg)](https://github.com/nuskey8/Csv-CSharp/releases)\n[![GitHub license](https://img.shields.io/github/license/nuskey8/Csv-CSharp.svg)](./LICENSE)\n\nEnglish | [日本語](./README_JA.md)\n\n![img](docs/img1.png)\n\nCsv-CSharp is a highly performant CSV (TSV) parser for .NET and Unity. It is designed to parse UTF-8 binaries directly and leverage Source Generators to enable serialization/deserialization between CSV (TSV) and object arrays with zero (or very low) allocation.\n\n## Installation\n\n### NuGet packages\n\nCsv-CSharp requires .NET Standard 2.1 or higher. The package can be obtained from NuGet.\n\n### .NET CLI\n\n```ps1\ndotnet add package CsvCSharp\n```\n\n### Package Manager\n\n```ps1\nInstall-Package CsvCSharp\n```\n\n### Unity\n\nYou can install Csv-CSharp in Unity by using [NugetForUnity](https://github.com/GlitchEnzo/NuGetForUnity). For details, refer to the NugetForUnity README.\n\n## Quick Start\n\nCsv-CSharp serializes/deserializes CSV data to and from arrays of classes/structs.\n\nDefine a class/struct and add the `[CsvObject]` attribute and the `partial` keyword.\n\n```cs\n[CsvObject]\npublic partial class Person\n{\n    [Column(0)]\n    public string Name { get; set; }\n\n    [Column(1)]\n    public int Age { get; set; }\n}\n```\n\nAll public fields/properties of a type marked with `[CsvObject]` must have either the `[Column]` or `[IgnoreMember]` attribute. (An analyzer will output a compile error if it does not find either attribute on public members.)\n\nThe `[Column]` attribute can specify a column index as an `int` or a header name as a `string`.\n\nTo serialize this type to CSV or deserialize it from CSV, use `CsvSerializer`.\n\n```cs\nvar array = new Person[]\n{\n    new() { Name = \"Alice\", Age = 18 },\n    new() { Name = \"Bob\", Age = 23 },\n    new() { Name = \"Carol\", Age = 31 },\n}\n\n// Person[] -\u003e CSV (UTF-8)\nbyte[] csv = CsvSerializer.Serialize(array);\n\n// Person[] -\u003e CSV (UTF-16)\nstring csvText = CsvSerializer.SerializeToString(array);\n\n// CSV (UTF-8) -\u003e Person[]\narray = CsvSerializer.Deserialize\u003cPerson\u003e(csv);\n\n// CSV (UTF-16) -\u003e Person[]\narray = CsvSerializer.Deserialize\u003cPerson\u003e(csvText);\n```\n\nSerialize has an overload that returns a UTF-8 encoded `byte[]`, and you can also pass a `Stream` or `IBufferWriter\u003cbyte\u003e` for writing. Deserialize accepts UTF-8 byte arrays as `byte[]` and also supports `string`, `Stream`, and `ReadOnlySequence\u003cbyte\u003e`.\n\nThe default supported types for fields are `sbyte`, `byte`, `short`, `ushort`, `int`, `uint`, `long`, `ulong`, `char`, `string`, `Enum`, `Nullable\u003cT\u003e`, `DateTime`, `TimeSpan`, and `Guid`. To support other types, refer to the Extensions section.\n\n## Serialization\n\nThe class/struct passed to `CsvSerializer` should have the `[CsvObject]` attribute and the `partial` keyword.\n\nBy default, fields and properties with the `[Column]` attribute are the targets for serialization/deserialization. The `[Column]` attribute is mandatory for public members, but you can target private members by adding the `[Column]` attribute.\n\n```cs\n[CsvObject]\npublic partial class Person\n{\n    [Column(0)]\n    public string Name { get; set; }\n\n    [Column(1)]\n    int age;\n\n    [IgnoreMember]\n    public int Age =\u003e age;\n}\n```\n\nTo specify header names instead of indices, use a string key.\n\n```cs\n[CsvObject]\npublic partial class Person\n{\n    [Column(\"name\")]\n    public string Name { get; set; }\n\n    [Column(\"age\")]\n    public int Age { get; set; }\n}\n```\n\nTo use member names as keys, specify `[CsvObject(keyAsPropertyName: true)]`. In this case, the `[Column]` attribute is not required.\n\n```cs\n[CsvObject(keyAsPropertyName: true)]\npublic partial class Person\n{\n    public string Name { get; set; }\n    public int Age { get; set; }\n}\n```\n\n## CsvDocument\n\nIf you need to directly parse CSV fields, you can use `CsvDocument`.\n\n```cs\nvar array = new Person[]\n{\n    new() { Name = \"Alice\", Age = 18 },\n    new() { Name = \"Bob\", Age = 23 },\n    new() { Name = \"Carol\", Age = 31 },\n};\n\nbyte[] csv = CsvSerializer.Serialize(array);\n\n// CSV (UTF-8) -\u003e CsvDocument\nvar document = CsvSerializer.ConvertToDocument(csv);\n\nforeach (var row in document.Rows)\n{\n    var name = row[\"Name\"].GetValue\u003cstring\u003e();\n    var age = row[\"Age\"].GetValue\u003cint\u003e();\n}\n```\n\n## Options\n\nYou can change CSV settings by passing `CsvOptions` to Serialize/Deserialize.\n\n```cs\nCsvSerializer.Serialize(array, new CsvOptions()\n{\n    HasHeader = true, // Include header row\n    AllowComments = true, // Allow comments starting with '#''\n    NewLine = NewLineType.LF, // Newline type\n    Separator = SeparatorType.Comma, // Separator character\n    QuoteMode = QuoteMode.Minimal, // Conditions for quoting fields (Minimal quotes only strings containing escape characters)\n    FormatterProvider = StandardFormatterProvider.Instance, // ICsvFormatterProvider to use\n});\n```\n\n## CSV Specifications\n\nThe default settings of Csv-CSharp generally follow the specifications outlined in [RFC 4180](https://www.rfc-editor.org/rfc/rfc4180.html). However, please note that for performance and practicality reasons, some specifications may be disregarded.\n\n- The default newline character is LF instead of CRLF.\n- Records with a mismatch in the number of fields can be read without errors being output; missing fields will be set to their default values.\n\n## Extensions\n\nInterfaces `ICsvFormatter\u003cT\u003e` and `ICsvFormatterProvider` are provided to customize field serialization/deserialization.\n\nUse `ICsvFormatter\u003cT\u003e` for type serialization/deserialization. Here is an example of implementing a formatter for a struct wrapping an `int`.\n\n```cs\npublic struct Foo\n{\n    public int Value;\n\n    public Foo(int value)\n    {\n        this.Value = value;\n    }\n}\n\npublic sealed class FooFormatter : ICsvFormatter\u003cFoo\u003e\n{\n    public Foo Deserialize(ref CsvReader reader)\n    {\n        var value = reader.ReadInt32();\n        return new Foo(value);\n    }\n\n    public void Serialize(ref CsvWriter writer, Foo value)\n    {\n        writer.WriteInt32(value.Value);\n    }\n}\n```\n\nNext, implement a formatter provider to retrieve the formatter.\n\n```cs\npublic class CustomFormatterProvider : ICsvFormatterProvider\n{\n    public static readonly ICsvFormatterProvider Instance = new CustomFormatterProvider();\n\n    CustomFormatterProvider()\n    {\n    }\n\n    static CustomFormatterProvider()\n    {\n        FormatterCache\u003cFoo\u003e.Formatter = new FooFormatter();\n    }\n\n    public ICsvFormatter\u003cT\u003e? GetFormatter\u003cT\u003e()\n    {\n        return FormatterCache\u003cT\u003e.Formatter;\n    }\n\n    static class FormatterCache\u003cT\u003e\n    {\n        public static readonly ICsvFormatter\u003cT\u003e Formatter;\n    }\n}\n```\n\nYou can set the created formatter provider in CsvOptions. The above `CustomFormatterProvider` only supports the `Foo` struct, so combine it with the standard formatter provider `StandardFormatterProvider`.\n\n```cs\n// Create a composite formatter provider combining multiple formatter providers\nvar provider = CompositeFormatterProvider.Create(\n    CustomFormatterProvider.Instance,\n    StandardFormatterProvider.Instance\n);\n\nCsvSerializer.Serialize(array, new CsvOptions()\n{\n    FormatterProvider = provider\n});\n```\n\n## License\n\nThis library is released under the MIT license.","funding_links":[],"categories":["Source Generators"],"sub_categories":["Serialization"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnuskey8%2FCsv-CSharp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnuskey8%2FCsv-CSharp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnuskey8%2FCsv-CSharp/lists"}