CSV.Net is a flexible and easy-to-use library for serializing and deserializing objects to and from CSV files. It leverages reflection to map CSV columns to object properties and supports custom formatting for numeric types based on culture-specific settings.
- Serialize and deserialize objects to/from CSV.
- Support for custom column names using
CsvColumnAttribute
. - Handles various numeric types (
float
,double
,decimal
) with custom formatting. - Configurable delimiter for CSV files (default is
;
). - Error handling during serialization and deserialization.
- Supports both CSV files with and without headers.
- Supports automatic mapping of CSV columns to object properties using reflection.
To use CSV.Net in your project, you can either clone this repository or add it as a dependency in your .csproj
file.
git clone https://github.com/Andy16823/CSV.Net.git
If you publish it as a NuGet package, you can install it via NuGet:
dotnet add package CSV.Net
using CSVNet;
var personList = new List<Person>
{
new Person { FirstName = "Markus", LastName = "Mustermann", Age = 30, Salary = 1200.50f },
new Person { FirstName = "Nadine", LastName = "Musterfrau", Age = 32, Salary = 1500.75f }
};
string filePath = "output.csv";
Converter.Serialize(personList, filePath);
using CSVNet;
string filePath = "input.csv";
var deserializedList = Converter.Deserialize<Person>(filePath);
You can use the CsvColumnAttribute
to specify how object properties should be mapped to CSV columns:
public class Person
{
[CsvColumn("First Name")]
public string FirstName { get; set; }
[CsvColumn("Last Name")]
public string LastName { get; set; }
[CsvColumn("Age")]
public int Age { get; set; }
[CsvColumn("Salary")]
public float Salary { get; set; }
}
This project is licensed under the MIT License - see the LICENSE file for details.
- Fork the repository.
- Create your feature branch (
git checkout -b feature/my-new-feature
). - Commit your changes (
git commit -am 'Add new feature'
). - Push to the branch (
git push origin feature/my-new-feature
). - Open a pull request.