Skip to content

Commit 73e2be2

Browse files
Tino KlijnDotNet2Web
authored andcommitted
updatet the documentation.
1 parent 0ce9ea8 commit 73e2be2

File tree

2 files changed

+34
-9
lines changed

2 files changed

+34
-9
lines changed

CsvCore/Documentation/CsvCoreReader.md

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,31 +54,28 @@ public class Foo(ICsvCoreReader csvCoreReader)
5454
}
5555
```
5656

57-
In case you receive a csv that does not match the model you are reading the data too, then you can use the `CsvPosition` attribute in the model.
58-
Using the `CsvPosition` attribute you can specify the position of the property in the csv file.
57+
In case you receive a csv that does not match the model you are reading the data too, then you can use the `Header` attribute in the model.
58+
Using the `Header` attribute you can specify the position of the property in the csv file.
5959

6060
CSV file
6161
```text
6262
Surname;Name;Birthdate;Email
6363
Bar;Foo;01/01/2025;foo@bar.com
6464
```
6565

66-
Be aware that the position is zero based!
67-
The first column in the csv file is position 0, the second column is position 1 and so on.
68-
6966
```csharp
7067
public class NotMatchingPersonModel
7168
{
72-
[CsvPosition(1)] // This property is in the second column in the csv file.
69+
[Header(2)] // This property is in the second column in the csv file.
7370
public string Name { get; set; }
7471

75-
[CsvPosition(0)] // This property is in the first column in the csv file.
72+
[Header(1)] // This property is in the first column in the csv file.
7673
public string Surname { get; set; }
7774

78-
[CsvPosition(2)] // This property is in the third column in the csv file.
75+
[Header(3)] // This property is in the third column in the csv file.
7976
public DateOnly BirthDate { get; set; }
8077

81-
[CsvPosition(3)] // This property is in the fourth column in the csv file.
78+
[Header(4)] // This property is in the fourth column in the csv file.
8279
public string Email { get; set; }
8380
}
8481
```

CsvCore/Documentation/CsvCoreWriter.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,31 @@ public class Foo(ICsvCoreWriter csvCoreWriter)
6363
```
6464

6565
Thats it, seems easy enough right?
66+
67+
In case you want to write your csv header different then the property names of you model, you can use the `Header` attribute in the model.
68+
Using the `Header` attribute you can specify the name of the header column in the csv file.
69+
70+
CSV file
71+
```text
72+
First_Name;Family Name;DateOfBirth;Contact Email
73+
Bar;Foo;01/01/2025;foo@bar.com
74+
```
75+
76+
```csharp
77+
public class NotMatchingPersonModel
78+
{
79+
[Header(name: "First_Name")]
80+
public string Name { get; set; }
81+
82+
[Header(name: "Family Name"))
83+
public string Surname { get; set; }
84+
85+
[Header(name: "DatOfBirth"))]
86+
public DateOnly BirthDate { get; set; }
87+
88+
[Header(name: "Contact Email")]
89+
public string Email { get; set; }
90+
}
91+
```
92+
93+
When you have the model all setup use the `CsvCoreWriter` to write the csv file, see the above section for the example.

0 commit comments

Comments
 (0)