Category: roslyn

  • [Video] 5 Minutes Roslyn Code Generators

    [Video] 5 Minutes Roslyn Code Generators

  • AOP with Roslyn–part 5 – getting line number right

    There is a problem with inserting lines  – the number of lines is not the same. What I mean by this? Look at this example       The DateTime.Now is on line 8 When we insert lines before and after each method,the DateTime.Now is on line 9 This is usually not so important  –…

  • AOP with Roslyn–part 4–custom code to the end of the method

      A good AOP needs also custom code to the beginning and to the end of the method. So we need to add formatter for the last line. That means that the MetodRewriter constructor will look like this:     More,we should put code at the beginning and at the end of the method And…

  • AOP with Roslyn–part 3–custom code at beginning of each method

    Last time(http://msprogrammer.serviciipeweb.ro/2017/11/27/aop-with-roslynpart-2/)  we have injected a new code into each method . However,this code was pretty much hardcoded into the MethodRewriter class – it was a simple Console.WriteLine(\”{nameClass}_{nameMethod}_{lineStartNumber}\”);   Now we want to can customize this code at the will of the programmer. For this,I have modified classes RewriteCode and MethodRewriter to accept a parameter…

  • AOP with Roslyn–part 2

    I want to transform code by injecting some simple code,like “Console.WriteLine(“method”) So this code:     should be modified to this code:     How I do the code: I derive from CSharpSyntaxRewriter and override the VisitMethodDeclaration  . I will construct a new node with the Console.WriteLine statement inserted     As test,I have created…

  • AOP with Roslyn

    What I am interested in is to make a tool that logs in when the program comes in and out of a method. It’s good for identifying problems in code and for logging. What already exists on the market: PostSharp – one of the best – see https://www.postsharp.net/alternatives Cecil http://www.mono-project.com/docs/tools+libraries/libraries/Mono.Cecil/ Fody https://github.com/Fody NConcern: https://github.com/Virtuoze/NConcern What…