Skip to content

Commit

Permalink
Merge pull request #11 from Fabian918/feature/Add_Quickstart
Browse files Browse the repository at this point in the history
Feature/add quickstart
  • Loading branch information
Fabian918 committed Apr 7, 2024
2 parents 82f3ee4 + 615dd0a commit ea5689e
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 52 deletions.
Binary file added AddNuget.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions CsvPortable/.idea/.idea.CsvPortable/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions CsvPortable/CsvPortable.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
14 changes: 14 additions & 0 deletions CsvPortable/HelloWorld/HelloWorld.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CsvPortable" Version="0.3.1" />
</ItemGroup>

</Project>
49 changes: 49 additions & 0 deletions CsvPortable/HelloWorld/Program.cs
Original file line number Diff line number Diff line change
@@ -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<Car>();
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; }
}

81 changes: 29 additions & 52 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,59 +1,36 @@
# CsvPortable
Simple, open &amp; 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<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)
}
};

// Write items as IEnumerable<T>
await ICsvPortable.ToStream(newAddresses, writeStream);
### Add the Package:

via IDE:
![alt text](AddNuget.png)

via terminal:

```
## Tutorials
[Export existing models](./Documentation/CreateReportsFromExistingModels.md)
dotnet add package CSVPortable
```

manual:
- add

```xml
<ItemGroup>
<PackageReference Include="CSVPortable" Version="0.3.1" />
</ItemGroup>
```
to the `.csproj` file.

### Code:
- [Hello World](./CsvPortable/HelloWorld/Program.cs)
- [Read & Write Files](./CsvPortable/ReadAndWriteFiles/Program.cs)
- [Export existing models](./Documentation/CreateReportsFromExistingModels.md)

0 comments on commit ea5689e

Please sign in to comment.