Category: roslyn

  • RSGC-Constructor – Deconstructor – part 5

        name CopyConstructor + Deconstructor 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 generate code for a POCO to generate copy constructor and deconstructor   The code that you start with is The code that you will use is   The code that is generated is Example Code: https://github.com/ignatandrei/RSCG_Examples/tree/main/CopyConstructor

  • RSGC-JSON to Class- part 4

        name JsonByExampleGenerator nuget https://www.nuget.org/packages/JsonByExampleGenerator/ link https://github.com/hermanussen/JsonByExampleGenerator/ author Robin Hermanussen This will generate C# classes from json files.   The code that you start with is The code that you will use is   The code that is generated is Example Code: https://github.com/ignatandrei/RSCG_Examples/tree/main/JsonToClass

  • RSGC-Enum-part 3

        name Enum 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 generate code to fast parsing a int or a string to an enum   The code that you start with is The code that you will use is   The code that is generated is Example Code: https://github.com/ignatandrei/RSCG_Examples/tree/main/Enum

  • RSCG- AppVersion–part 2

        name ThisAssembly nuget https://www.nuget.org/packages/ThisAssembly link https://www.clarius.org/ThisAssembly/ author Daniel Cazzulino The ThisAssembly.Info allows you access to the Assembly Information as constants,instead of going to reflection each time. I found useful to see the assembly version right away in any project that I have.   The code that you start with is in .csproj <PropertyGroup>…

  • RSCG–part 1

    Roslyn Source Code Generators are a easy way to generate automatically code that can be injected at compile time. This code can be generated on some template file or based on existing code or both . It works by intercepting at compile time the result of compilation of the existing source code and adding to…

  • AOPMethods–dogfooding

    I was trying to apply AOPMethods to – surprise! –  AOPMethods project itself. And I have discovered a new reason: I do not want to make the methods public. I just want to put try/catch around them to know what is wrong. The fast – and not so good – idea was to transform MethodPrefix…

  • AOP Methods–Problems in running and solving

    The problems that I have encountered were: 1.  The ThisAssembly  RoslynGenerator that I use should not be put as reference in the nuget. I have fixed this by adding <PackageReference Include=”ThisAssembly.AssemblyInfo” Version=”1.0.0″ ReferenceOutputAssembly=”false” /> 2. I have problems generating code to async code with Task . The problem was that I have added logging (…

  • AOP Methods–Code

    The code is not so much different from SkinnyControllers : Implement ISourceGenerator,putting the Generator attribute on the class [Generator]    public partial class AutoActionsGenerator : ISourceGenerator inspecting the classes if they have the common attribute,generating code with Scriban The problem was : How can the AOPMethods can differentiate between the private function that must be made…

  • AOP Methods–Introduction

    As I have done with Roslyn for SkinnyControllers,I said – what about generating public methods at compile time ? For example,what if this method private string pubFullName() { return FirstName + ” ” + LastName; }   is transformed into this public string FullName( [CallerMemberName] string memberName = “”, [CallerFilePath] string sourceFilePath = “”, [CallerLineNumber]…

  • AutoActions for Skinny controllers–custom template

    Now I want to let the user make his own template. For this,I have enriched the attribute AutoActionsAttribute with a public string CustomTemplateFileName { get; set; }   The code was pretty easy,just reading from GeneratorExecutionContext . AdditionalFiles instead of reading from the template in the dll     There are 2 small catches 1…