Friday 29 July 2016

Writing Roslyn based Code Analyzer and Fixer - 2

Previous post talked about my code analyzer that identifies Code Analysis suppressions in source files and provides fix for the same.

So how does it work.

Reporting diagnostics:


It is as simple as looking at all "attribute lists" and checking if any of the attributes is "SuppressMessage" in a file that is not called "GlobalSuppressions.cs". I know it is not the most optimal thing but I guess it works for me for now.

Roslyn's new version provides a new and elegant way of dealing with code through IAction and Syntax Generators. Here I used "RegisterSyntaxNodeAction" method.

Fixing the warning:


Register your code fix.


Modify the solution. Basically do 3 things:
   a. Add GlobalSuppressions file if it is not present.
   b. Modify the current source file.
   c. Modify the GlobalSuppressions file.

You would notice that I have added some hacks like appending "assembly:" text or changing "SuppressMessage" to "System.Diagnostics.CodeAnalysis.SuppressMessage" to ensure that there is no dependency over using blocks. I am sure you can improve over this.


Happy code analysis!!

1 comment:

  1. Essay writers may use the idea unreliable sites present but need reliable resources to cite and confirm the collected information. Below are examples of unreliable sources that require confirmation with a reliable source. best essay writing service reddit

    ReplyDelete