From 8bb35bed6e29f00947e771bd2533da7598a0f3e9 Mon Sep 17 00:00:00 2001 From: Thorsten Sommer Date: Tue, 21 May 2024 13:40:30 +0200 Subject: [PATCH] Prepared 1.1.0 release --- .../CSV Metrics Logger Generator.csproj | 6 ++-- CSV Metrics Logger Generator/README.md | 34 ++++++++++++++++--- CSV Metrics Logger/CSV Metrics Logger.csproj | 6 ++-- CSV Metrics Logger/README.md | 34 ++++++++++++++++--- README.md | 34 ++++++++++++++++--- 5 files changed, 93 insertions(+), 21 deletions(-) diff --git a/CSV Metrics Logger Generator/CSV Metrics Logger Generator.csproj b/CSV Metrics Logger Generator/CSV Metrics Logger Generator.csproj index c89277e..8969d40 100644 --- a/CSV Metrics Logger Generator/CSV Metrics Logger Generator.csproj +++ b/CSV Metrics Logger Generator/CSV Metrics Logger Generator.csproj @@ -10,9 +10,9 @@ true false - 1.0.0 - 1.0.0 - 1.0.0 + 1.1.0 + 1.1.0 + 1.1.0 Thorsten Sommer https://devops.tsommer.org/open-source/dotnet/csv-metrics-logger https://devops.tsommer.org/open-source/dotnet/csv-metrics-logger diff --git a/CSV Metrics Logger Generator/README.md b/CSV Metrics Logger Generator/README.md index 643f477..beaabc9 100644 --- a/CSV Metrics Logger Generator/README.md +++ b/CSV Metrics Logger Generator/README.md @@ -18,7 +18,7 @@ List testData = ]; var filename = Path.GetTempFileName(); -await using var storage = CSVStorage.Create(fileName); +await using var storage = CSVStorage.Create(filename); foreach (var data in testData) storage.Write(data); @@ -26,13 +26,37 @@ foreach (var data in testData) You might use `storage.Write` from multiple threads. The logger will handle the synchronization for you. -CSV Metrics Logger uses a source generator. You have to use the following NuGet packages: +CSV Metrics Logger uses a source generator. You need to use the following NuGet packages: ```xml - - + + ``` -Your data must be modeled as a structure; classes are not supported. It does not matter if you are using a (readonly) record struct or a regular struct. The only requirement is that the struct must be a partial struct. The source generator will generate the missing part of the struct for you. Each public property will be used as a column in the CSV file. The property type might be any type, as long as it supports the `ToString(CultureInfo)` method. +Your data must be modeled as a structure; classes are not supported. It does not matter if you are using a (readonly) record struct or a regular struct. The only requirement is that the struct must be a partial struct. The source generator will generate the missing part of the struct for you. Each public property will be used as a column in the CSV file. The property type can be any type, as long as it supports the ToString() method. + +Additionally, you can use generic type parameters in your struct, as long as there is a suitable ToString() overload. Here is an example: + +```csharp +using CSV_Metrics_Logger; + +[CSVRecord] +public readonly partial record struct GenericTestData(string Name, sbyte Age, TNum Measure) where TNum : IFloatingPointIeee754; + +List testData = +[ + new TestData("Name 1", 14, 47.53f), + new TestData("Name 2", 25, 19.84f), + new TestData("Name 3", 36, 38.78f), + new TestData("Name 4", 47, 17.25f), + new TestData("Name 5", 58, 73.89f), +]; + +var filename = Path.GetTempFileName(); +await using var storage = CSVStorage>.Create(filename); + +foreach (var data in testData) + storage.Write(data); +``` For each data structure, you create a CSVStorage instance. The CSVStorage instance is a disposable object. You must dispose of it when you are done with it. When the CSV file already exists, the CSVStorage object will append data to the existing file; the header will not be written again. \ No newline at end of file diff --git a/CSV Metrics Logger/CSV Metrics Logger.csproj b/CSV Metrics Logger/CSV Metrics Logger.csproj index b684756..dc0f3a9 100644 --- a/CSV Metrics Logger/CSV Metrics Logger.csproj +++ b/CSV Metrics Logger/CSV Metrics Logger.csproj @@ -9,9 +9,9 @@ CS8600;CS8602;CS8603 true - 1.0.0 - 1.0.0 - 1.0.0 + 1.1.0 + 1.1.0 + 1.1.0 Thorsten Sommer https://devops.tsommer.org/open-source/dotnet/csv-metrics-logger https://devops.tsommer.org/open-source/dotnet/csv-metrics-logger diff --git a/CSV Metrics Logger/README.md b/CSV Metrics Logger/README.md index 643f477..beaabc9 100644 --- a/CSV Metrics Logger/README.md +++ b/CSV Metrics Logger/README.md @@ -18,7 +18,7 @@ List testData = ]; var filename = Path.GetTempFileName(); -await using var storage = CSVStorage.Create(fileName); +await using var storage = CSVStorage.Create(filename); foreach (var data in testData) storage.Write(data); @@ -26,13 +26,37 @@ foreach (var data in testData) You might use `storage.Write` from multiple threads. The logger will handle the synchronization for you. -CSV Metrics Logger uses a source generator. You have to use the following NuGet packages: +CSV Metrics Logger uses a source generator. You need to use the following NuGet packages: ```xml - - + + ``` -Your data must be modeled as a structure; classes are not supported. It does not matter if you are using a (readonly) record struct or a regular struct. The only requirement is that the struct must be a partial struct. The source generator will generate the missing part of the struct for you. Each public property will be used as a column in the CSV file. The property type might be any type, as long as it supports the `ToString(CultureInfo)` method. +Your data must be modeled as a structure; classes are not supported. It does not matter if you are using a (readonly) record struct or a regular struct. The only requirement is that the struct must be a partial struct. The source generator will generate the missing part of the struct for you. Each public property will be used as a column in the CSV file. The property type can be any type, as long as it supports the ToString() method. + +Additionally, you can use generic type parameters in your struct, as long as there is a suitable ToString() overload. Here is an example: + +```csharp +using CSV_Metrics_Logger; + +[CSVRecord] +public readonly partial record struct GenericTestData(string Name, sbyte Age, TNum Measure) where TNum : IFloatingPointIeee754; + +List testData = +[ + new TestData("Name 1", 14, 47.53f), + new TestData("Name 2", 25, 19.84f), + new TestData("Name 3", 36, 38.78f), + new TestData("Name 4", 47, 17.25f), + new TestData("Name 5", 58, 73.89f), +]; + +var filename = Path.GetTempFileName(); +await using var storage = CSVStorage>.Create(filename); + +foreach (var data in testData) + storage.Write(data); +``` For each data structure, you create a CSVStorage instance. The CSVStorage instance is a disposable object. You must dispose of it when you are done with it. When the CSV file already exists, the CSVStorage object will append data to the existing file; the header will not be written again. \ No newline at end of file diff --git a/README.md b/README.md index 643f477..beaabc9 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ List testData = ]; var filename = Path.GetTempFileName(); -await using var storage = CSVStorage.Create(fileName); +await using var storage = CSVStorage.Create(filename); foreach (var data in testData) storage.Write(data); @@ -26,13 +26,37 @@ foreach (var data in testData) You might use `storage.Write` from multiple threads. The logger will handle the synchronization for you. -CSV Metrics Logger uses a source generator. You have to use the following NuGet packages: +CSV Metrics Logger uses a source generator. You need to use the following NuGet packages: ```xml - - + + ``` -Your data must be modeled as a structure; classes are not supported. It does not matter if you are using a (readonly) record struct or a regular struct. The only requirement is that the struct must be a partial struct. The source generator will generate the missing part of the struct for you. Each public property will be used as a column in the CSV file. The property type might be any type, as long as it supports the `ToString(CultureInfo)` method. +Your data must be modeled as a structure; classes are not supported. It does not matter if you are using a (readonly) record struct or a regular struct. The only requirement is that the struct must be a partial struct. The source generator will generate the missing part of the struct for you. Each public property will be used as a column in the CSV file. The property type can be any type, as long as it supports the ToString() method. + +Additionally, you can use generic type parameters in your struct, as long as there is a suitable ToString() overload. Here is an example: + +```csharp +using CSV_Metrics_Logger; + +[CSVRecord] +public readonly partial record struct GenericTestData(string Name, sbyte Age, TNum Measure) where TNum : IFloatingPointIeee754; + +List testData = +[ + new TestData("Name 1", 14, 47.53f), + new TestData("Name 2", 25, 19.84f), + new TestData("Name 3", 36, 38.78f), + new TestData("Name 4", 47, 17.25f), + new TestData("Name 5", 58, 73.89f), +]; + +var filename = Path.GetTempFileName(); +await using var storage = CSVStorage>.Create(filename); + +foreach (var data in testData) + storage.Write(data); +``` For each data structure, you create a CSVStorage instance. The CSVStorage instance is a disposable object. You must dispose of it when you are done with it. When the CSV file already exists, the CSVStorage object will append data to the existing file; the header will not be written again. \ No newline at end of file