Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ignatandrei/RSCG_Utils
Roslyn Source Code Generators Utils
https://github.com/ignatandrei/RSCG_Utils
dotnet roslyn-generator rscg
Last synced: about 1 month ago
JSON representation
Roslyn Source Code Generators Utils
- Host: GitHub
- URL: https://github.com/ignatandrei/RSCG_Utils
- Owner: ignatandrei
- License: mit
- Created: 2023-05-01T03:20:00.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-07-09T21:54:16.000Z (5 months ago)
- Last Synced: 2024-08-01T22:43:31.903Z (4 months ago)
- Topics: dotnet, roslyn-generator, rscg
- Language: C#
- Homepage: https://www.nuget.org/packages/rscgutils
- Size: 79.1 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- RSCG_Examples - https://github.com/ignatandrei/RSCG_Utils
README
# RSCG_Utils
Roslyn Source Code Generators Utils
[![pack to nuget](https://github.com/ignatandrei/RSCG_Utils/actions/workflows/dotnet.yml/badge.svg)](https://github.com/ignatandrei/RSCG_Utils/actions/workflows/dotnet.yml)
[![pack to nuget](https://img.shields.io/nuget/dt/rscgutils?style=for-the-badge)](https://www.nuget.org/packages/rscgutils)
# Usage
## Additional Files
Allow you to see additional files directly as C# const. For this, please add some .gen. files to the project.
In your csproj
```xml
```
In the code
```csharp
//see https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/tokens/raw-string
string x= MyAdditionalFiles.Second_gen_txt;
```To debug, you can add into the .csproj
```xmltrue
$(BaseIntermediateOutputPath)\GeneratedX```
More details at http://msprogrammer.serviciipeweb.ro/2023/05/08/file-to-csharp-const/
## Json2Class
If you have an additional json file, you can have a file from this
```xml
```
And you can have from the code
```csharpvar json = System.Text.Json.JsonSerializer
.Deserialize(MyAdditionalFiles.my_gen_json);ArgumentNullException.ThrowIfNull( json );
Console.WriteLine( ":hosts"+json.AllowedHosts );```
## Memoization of function returns
Put _MemoPure and the return of the function will be memo-ized
```csharp
public long Test_MemoPure()
{
Console.WriteLine("calculating type");
return this.GetType().ToString().GetHashCode();
}
public async Task fib(long nr)
{
await Task.Delay(1000);
//Console.WriteLine("calculated value for " + nr);
if (nr <= 1) return 1;
if (nr == 2) return 2;
return await fib(nr - 1) + await fib(nr - 1);
}public async Task fibonacci_MemoPure(long nr)
{
if (nr <= 1) return 1;
if (nr == 2) return 2;
await Task.Delay(1000);
return await fibonacci(nr - 1) + await fibonacci(nr - 1);}
```And call
```csharp
fibTest f = new();
Console.WriteLine("first time :" + f.Test());
Console.WriteLine("second time :" + f.Test());Console.WriteLine(DateTime.Now.ToString("mm_ss"));
Console.WriteLine("no memo :"+await f.fib(5));
Console.WriteLine(DateTime.Now.ToString("mm_ss"));
Console.WriteLine("memo :" + await f.fibonacci(5));
Console.WriteLine(DateTime.Now.ToString("mm_ss"));
Console.WriteLine("FAST memo :" + await f.fibonacci(5));
Console.WriteLine(DateTime.Now.ToString("mm_ss"));```
# More Roslyn Source Code Generators
You can find more RSCG with examples at [Roslyn Source Code Generators](https://ignatandrei.github.io/RSCG_Examples/v2/)