-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,57 @@ | ||
# CsvPortable | ||
Simple, open & free Csv mapper libary for C# .NET Core | ||
|
||
## Getting Started | ||
|
||
```csharp | ||
await using var serviceProvider = serviceCollection.BuildServiceProvider(); | ||
var logger = serviceProvider.GetRequiredService<ILogger<Program>>(); | ||
|
||
// ----- Read csv File | ||
// Open File Stream | ||
await using var fileStream = File.OpenRead("./Addresses.csv"); | ||
|
||
|
||
// Reading items as IEnumerable<T> | ||
int index = 1; | ||
foreach (var address in ICsvPortable.FromStream<Address>(fileStream)) | ||
{ | ||
logger.LogInformation( | ||
"Address '{Index}' - '{Street}, {City}, {Country}, {ZipCode}, {Created}'", | ||
index, | ||
address.Street, | ||
address.City, | ||
address.Country, | ||
address.ZipCode, | ||
address.Created | ||
); | ||
index++; | ||
} | ||
|
||
// ----- Write csv File | ||
await using var writeStream = File.OpenWrite("./newAddresses.csv"); // Create File | ||
|
||
List<Address> newAddresses = new List<Address>() | ||
{ | ||
new Address | ||
{ | ||
Street = "Street 1", | ||
City = "City 1", | ||
Country = "Country 1", | ||
ZipCode = 12345, | ||
Created = DateTime.Now | ||
}, | ||
new Address() | ||
{ | ||
Street = "Street 2", | ||
City = "City 2", | ||
Country = "Country 4", | ||
ZipCode = 54321, | ||
Created = new DateTime(2012, 12, 31) | ||
} | ||
}; | ||
|
||
``` |