SimpleObjects2CSV 2.0.0
dotnet add package SimpleObjects2CSV --version 2.0.0
NuGet\Install-Package SimpleObjects2CSV -Version 2.0.0
<PackageReference Include="SimpleObjects2CSV" Version="2.0.0" />
<PackageVersion Include="SimpleObjects2CSV" Version="2.0.0" />
<PackageReference Include="SimpleObjects2CSV" />
paket add SimpleObjects2CSV --version 2.0.0
#r "nuget: SimpleObjects2CSV, 2.0.0"
#:package SimpleObjects2CSV@2.0.0
#addin nuget:?package=SimpleObjects2CSV&version=2.0.0
#tool nuget:?package=SimpleObjects2CSV&version=2.0.0
SimpleObjects2CSV
A tiny object-to-CSV exporter for simple .NET admin tools, tests, support dumps, and quick internal exports.
Convert a collection of plain objects into CSV using public properties as columns. No mapping profiles, no CSV reading, no heavy dependencies.
Install
dotnet add package SimpleObjects2CSV
Getting a CSV string
using SimpleObjects2CSV;
var people = new List<Person>
{
new() { Name = "Alice", Age = 30 },
new() { Name = "Bob", Age = 25 },
};
string csv = CSV.GetCSVString(people);
// Age,Name
// 30,Alice
// 25,Bob
IEnumerable<T> is supported:
string csv = CSV.GetCSVString(people.AsEnumerable());
List<string> exports each item as a single Value column:
string csv = CSV.GetCSVString(new List<string> { "alpha", "beta" });
// Value
// alpha
// beta
Writing a CSV file
// filename + directory (legacy API)
CSV.ExportCSV(people, "people.csv", @"C:\Exports");
// full file path
CSV.ExportCSV(people, @"C:\Exports\people.csv");
// write an existing CSV string
CSV.ExportCSV(csv, "people.csv", @"C:\Exports");
Directories are created automatically. Files are written as UTF-8 without BOM.
Skipping properties with [CsvIgnore]
public class User
{
public string Name { get; set; }
[CsvIgnore]
public string Password { get; set; }
}
Custom column headers with [CsvName]
public class User
{
[CsvName("Display Name")]
public string FullName { get; set; }
}
Headers containing commas or quotes are escaped automatically.
Async export
await CSV.ExportCSVAsync(people, @"C:\Exports\people.csv");
await CSV.ExportCSVAsync(people, "people.csv", @"C:\Exports", cancellationToken: cancellationToken);
Formatting notes
- Columns are ordered alphabetically by property name (not declaration order).
- Column headers and values are CSV-escaped when they contain commas, quotes, or newlines.
List<string>/IEnumerable<string>exports each string as a singleValuecolumn.- Types with no exportable properties throw
InvalidOperationException. - Duplicate
[CsvName]headers on the same type throwInvalidOperationException. - Properties hidden with
newon a derived type use the derived declaration. - Null property values export as empty fields.
- Null items in the source collection are skipped (no row is written for them).
- Numbers, decimals, floats, and doubles use invariant culture by default. Floats and doubles use round-trip (
R) format. DateTime,DateTimeOffset,DateOnly, andTimeOnlyalways use invariant ISO 8601 (O) format, regardless ofIFormatProvider.- Booleans use invariant
True/Falsetext;IFormatProviderdoes not change them. - Pass an
IFormatProviderto format numeric values with a specific culture:
string csv = CSV.GetCSVString(people, new CultureInfo("de-DE"));
CSV.ExportCSV(people, "people.csv", @"C:\Exports", new CultureInfo("de-DE"));
- Async methods honour
CancellationTokenduring file writes. Onnetstandard2.0, cancellation is checked between write chunks.
Security note
CSV files opened in spreadsheet applications may execute formulas when a cell value begins with =, +, -, @, or a tab character. Sanitise or prefix untrusted values if exports may be opened in Excel or similar tools.
License
Apache-2.0
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. 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 is compatible. 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- No dependencies.
-
net8.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.