diff --git a/AddNuget.png b/AddNuget.png new file mode 100644 index 0000000..9276e98 Binary files /dev/null and b/AddNuget.png differ diff --git a/CsvPortable/.idea/.idea.CsvPortable/.idea/.gitignore b/CsvPortable/.idea/.idea.CsvPortable/.idea/.gitignore index 495c3fc..f70c6ff 100644 --- a/CsvPortable/.idea/.idea.CsvPortable/.idea/.gitignore +++ b/CsvPortable/.idea/.idea.CsvPortable/.idea/.gitignore @@ -11,3 +11,5 @@ # Datasource local storage ignored files /dataSources/ /dataSources.local.xml +# GitHub Copilot persisted chat sessions +/copilot/chatSessions diff --git a/CsvPortable/CsvPortable.sln b/CsvPortable/CsvPortable.sln index b8e52c4..a645ce9 100644 --- a/CsvPortable/CsvPortable.sln +++ b/CsvPortable/CsvPortable.sln @@ -12,6 +12,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Examples", "Examples", "{47 EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ReadAndWriteFiles", "ReadAndWriteFiles\ReadAndWriteFiles.csproj", "{A5192D06-4ECF-43FF-917E-346B167E1B51}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HelloWorld", "HelloWorld\HelloWorld.csproj", "{05B9CAF6-6822-4299-A363-229BCB004F20}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -34,9 +36,14 @@ Global {A5192D06-4ECF-43FF-917E-346B167E1B51}.Debug|Any CPU.Build.0 = Debug|Any CPU {A5192D06-4ECF-43FF-917E-346B167E1B51}.Release|Any CPU.ActiveCfg = Release|Any CPU {A5192D06-4ECF-43FF-917E-346B167E1B51}.Release|Any CPU.Build.0 = Release|Any CPU + {05B9CAF6-6822-4299-A363-229BCB004F20}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {05B9CAF6-6822-4299-A363-229BCB004F20}.Debug|Any CPU.Build.0 = Debug|Any CPU + {05B9CAF6-6822-4299-A363-229BCB004F20}.Release|Any CPU.ActiveCfg = Release|Any CPU + {05B9CAF6-6822-4299-A363-229BCB004F20}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(NestedProjects) = preSolution {A5192D06-4ECF-43FF-917E-346B167E1B51} = {472365B1-BDE3-4247-A6FF-9CECC3B871B6} {3C778FB2-CE4F-4FAB-B85D-459A63BE9C21} = {472365B1-BDE3-4247-A6FF-9CECC3B871B6} + {05B9CAF6-6822-4299-A363-229BCB004F20} = {472365B1-BDE3-4247-A6FF-9CECC3B871B6} EndGlobalSection EndGlobal diff --git a/CsvPortable/HelloWorld/HelloWorld.csproj b/CsvPortable/HelloWorld/HelloWorld.csproj new file mode 100644 index 0000000..eb67898 --- /dev/null +++ b/CsvPortable/HelloWorld/HelloWorld.csproj @@ -0,0 +1,14 @@ + + + + Exe + net8.0 + enable + enable + + + + + + + diff --git a/CsvPortable/HelloWorld/Program.cs b/CsvPortable/HelloWorld/Program.cs new file mode 100644 index 0000000..f7aa53c --- /dev/null +++ b/CsvPortable/HelloWorld/Program.cs @@ -0,0 +1,49 @@ +// See https://aka.ms/new-console-template for more information + + +using CsvPortable.Interfaces; + +Console.WriteLine("Hello World CsvPortable!"); + +Car car = new Car() +{ + Id = 1, + Name = "Hello World CsvPortable!", + Engine = new Engine() + { + PS = 250, + Type = Engine.EngineType.Hybrid + } +}; + +// Creates the header row of the csv. +var csvHeader = ICsvPortable.ExportDefinition(); +Console.WriteLine(csvHeader); +// Console output: Id;Name;PS;Type + +// Creates a csv row with the values of the given object. +var csvValues = ICsvPortable.ExportToCsvLine(car); +Console.WriteLine(csvValues); +// Console output: "1";"Hello World CsvPortable!";"250";"Hybrid" + + +class Car +{ + public int Id { get; set; } + public string Name { get; set; } + + public Engine Engine { get; set; } +} + +class Engine +{ + public enum EngineType + { + Electric, + Hybrid, + Gasoline + } + public int PS { get; set; } + public EngineType Type { get; set; } +} + diff --git a/README.md b/README.md index 1dd58c2..896b20a 100644 --- a/README.md +++ b/README.md @@ -1,59 +1,36 @@ # CsvPortable Simple, open & free Csv mapper libary for C# .NET Core +## Core Features +- easy **Serialization** and **Deserialization** of C# Objects +- Objects that contain Objects are supported +- Stream support for easy Integration + ## Getting Started -```csharp -// ----- 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) - } -}; - -// Write items as IEnumerable -await ICsvPortable.ToStream(newAddresses, writeStream); +### Add the Package: + +via IDE: +![alt text](AddNuget.png) + +via terminal: ``` -## Tutorials -[Export existing models](./Documentation/CreateReportsFromExistingModels.md) \ No newline at end of file +dotnet add package CSVPortable +``` + +manual: +- add + +```xml + + + +``` +to the `.csproj` file. + +### Code: +- [Hello World](./CsvPortable/HelloWorld/Program.cs) +- [Read & Write Files](./CsvPortable/ReadAndWriteFiles/Program.cs) +- [Export existing models](./Documentation/CreateReportsFromExistingModels.md) +