From fd9f3d0552fb8b91f47cd43dc9c054d6b08bd411 Mon Sep 17 00:00:00 2001 From: Fabian Hering <70378443+Fabian918@users.noreply.github.com> Date: Fri, 8 Dec 2023 17:54:26 +0100 Subject: [PATCH] Update README.md --- README.md | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/README.md b/README.md index 98d1471..4faaaeb 100644 --- a/README.md +++ b/README.md @@ -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>(); + +// ----- Read csv File + +// Open File Stream +await using var fileStream = File.OpenRead("./Addresses.csv"); + + +// Reading items as IEnumerable +int index = 1; +foreach (var address in ICsvPortable.FromStream
(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
newAddresses = new List
() +{ + 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) + } +}; + +```