Category: roslyn

  • TILT-Server Timing in Browser-part 19

    For see fast what is happening with your server,you can use the Server Timing API. One of the implementations for .NET is https://github.com/tpeczek/Lib.AspNetCore.ServerTiming . Not a big deal – implemented separately with AOPMethodsCommon – but I think it is a good idea to use it. The implementation was straightforward builder.Services.AddScoped<ServerTiming>(); var app = builder.Build(); app.UseServerTiming();…

  • DIForFunctions–improving generating of a constructor for a existing class with Roslyn

    It is not so difficult to generate a new constructor for a existing class with Roslyn – however,there are some difficulties: 1. The original class must be declared “partial” – you cannot declare the second as partial if the first was not 2.  The new class must be in the same namespace ( or without…

  • DIForFunctions – Improving constructor–part 5

    I have received a suggestion : what if we just put into constructor what we need,and everything else ( such as ILogger ) are into fields ? The Roslyn Source Code Generator will generate a constructor that calls the this constructor  and will assign fields needed. Let’s give an example : We wrote public partial…

  • DIForFunctions–what it does- part 4

    You can find a demo at https://github.com/ignatandrei/FunctionsDI/tree/main/src/FunctionsWithDI  – see TestCOnsoleAPP. But let’s write here also Generate (constructor) and functions calls similar with ASP.NET Core WebAPI ( [FromServices] will be provided by DI ) Also,verifies for null . Usage Reference into the csproj <ItemGroup> <PackageReference Include=”RSCG_FunctionsWithDI” Version=”2022.6.19.1605″ ReferenceOutputAssembly=”false” OutputItemType=”Analyzer” /> <PackageReference Include=”RSCG_FunctionsWithDI_Base” Version=”2022.6.19.1605″ /> </ItemGroup> Then…

  • DI for Functions- work–part 2

    Let’s begin with tests  – we need to have a class with multiple functions that have multiple [FromServices} parameter. Like public bool TestMyFunc1([FromServices] TestDI1 t1,[FromServices] TestDI2 t2,int x,int y)         {             return true;         }         public bool TestMyFunc2([FromServices] TestDI1 t12,  int x,int y)         {             return true;         } // more others Because there are multiple functions,I need to…

  • Templating Roslyn Source Code Generators

    I want that,when I generate code with Roslyn,to have a template that I can easy modify to generate code . Also,I want to let the user ( the programmer,in this case) modify this template  – maybe he has better ideas than me. For reading from the RSCG,is pretty simple: Make as an embedded resource and…

  • [RSCG]–About My Software

    I have made a new improvement to my Roslyn Source Code Generator,AMS . Until now it just said the time and the commit date in a CI scenario  ( Git ( GitLab,GitHub),Azure …) Now –  what if it can list all the merge requests between 2 dates ,so you can see what is new ?  Now…

  • FileExtension– export data from CSV–part 2

    First,is how to export data from table (https://en.wikipedia.org/wiki/List_of_file_signatures) into classes . First,the table must be transformed into a more programmatic recognizable way – like a CSV  – see https://github.com/ignatandrei/FileExtension/blob/master/src/RSCG_GCK/offset0.txt Then a solution is to have into the dll ( as embedded resource or as a file) . The second solution,more complicated,is to use Roslyn Source…

  • Evolving Roslyn Source Code Generators

    I am a big fan of Roslyn Source Code Generators – you can read about at https://github.com/dotnet/roslyn/blob/main/docs/features/source-generators.md and https://devblogs.microsoft.com/dotnet/introducing-c-source-generators/. I have tested,until now,27 examples and discovered other 53 RSCG – you can read about at https://github.com/ignatandrei/RSCG_Examples and download the book from  https://ignatandrei.github.io/RSCG_Examples/ Also,Microsoft is dogfooding this by using at Blazor ( https://devblogs.microsoft.com/aspnet/asp-net-core-updates-in-net-6-preview-2/#razor-compiler-updated-to-use-source-generators ),JSON.NET https://devblogs.microsoft.com/dotnet/try-the-new-system-text-json-source-generator/ .…

  • RSCG Example – AOPMarker for CI Builds – part 30

        name AOPMarkerCI nuget https://www.nuget.org/packages/AOPMethodsCommon/ https://www.nuget.org/packages/AOPMethodsGenerator/ link http://msprogrammer.serviciipeweb.ro/category/roslyn/ author Andrei Ignat This will tracing methods marked with AOPMarkerMethod in CI builds. Does not affect the code run by the programmer.   The code that you start with is The code that you will use is   The code that is generated is Example Code:…