Category: roslyn

  • 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…

  • AutoActions for Skinny controllers–code improvements and more docs

    I realized that this code Assembly.GetExecutingAssembly(); was executing for each controller. So I decided to move to a class variable and attribute once. Also,I may want to have all fields – so I decided to express via a special field * The code modifications were,thanks to Linq,pretty small: bool All = fields.Contains(“*”); var memberFields =…

  • AutoActions for Skinny controllers-documentation improvements

    One improvement is to move  Initialize in other partial class. . It was difficult every time I need to activate the debugger public void Initialize(GeneratorInitializationContext context)         {             context.RegisterForSyntaxNotifications(() => new SyntaxReceiverFields());             //in development             //Debugger.Launch();         } Second was to improve the Nuget package description. I have added <Version>2020.11.28.2108</Version>    <Authors>Andrei Ignat</Authors>    <PackageTags>RoslynCodeGenerators C# CSharp SkinnyControllers</PackageTags>    <PackageProjectUrl>https://github.com/ignatandrei/AOP_With_Roslyn</PackageProjectUrl>   …