Please update documentation regarding attributes.
When writing csv when you use a record like this:
public record Foo( [Name("Foobar")] string bar);
It will not write the csv using the Name attribute as expected. Reading does work. Please add this to the documentation, this will save people some headaches :).
@JBastiaan Am I doing something wrong when using a record? I just tried the syntax listed above and it doesn't work, but it does work when I declare getters and setters.
// This one fails
public record Export([Name("id")] string Id, [Name("email")] string Email, [Name("date")] DateTime Date);
CsvHelper.HeaderValidationException: Header with name 'id'[0] was not found.
Header with name 'email'[0] was not found.
Header with name 'date'[0] was not found.
// This one works
public record Export
{
[Name("id")]
public string Id { get; set; } = default!;
[Name("email")]
public string Email { get; set; } = default!;
[Name("date")]
public DateTime Date { get; set; } = default!;
}
I ran into this, as well. a documentation fix would be cool; it'd be cooler if [Name] worked with records :P
@BenMakesGames There is an issue for this. https://github.com/JoshClose/CsvHelper/issues/2048 It explains the issues regarding this.
There is a discussion that no one has commented on yet regarding it too. https://github.com/JoshClose/CsvHelper/discussions/2052
I suppose I'll just go and do whatever I want since no one has chimed in.