-
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.
Merge pull request #11 from Fabian918/feature/Add_Quickstart
Feature/add quickstart
- Loading branch information
Showing
6 changed files
with
101 additions
and
52 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -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> |
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 |
---|---|---|
@@ -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; } | ||
} | ||
|
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,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<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) | ||
|