This tool is known internally within Microsoft as StyleCop, and has been used for many years now to help teams enforce a common set of best practices for layout, readability, maintainability, and documentation of C# source code.
I am always looking for a way to improve my coding style and I was hoping to find out more about what the Microsoft coding style looks like. And I was fortunate: The tool actually ships with a lot of baked in rules … which I would be happy to comply to, if I could just find out how to comply to them. So I set out to find out how that tool works – and how to tweak and adjust the build in sets. Hint: Installation directory is “%ProgramFiles%/Microsoft Source Analysis Tool for C#”.
What the tool basically does is:
- find all files in the current solution
- Create a parse tree of any given file
- load all dlls in installation folder and find all classes derived from Microsoft.SourceAnalysis.SourceAnalyzer
- Execute each analyzer
To find out more about the rules that ship with Source Analysis (loaded in step 3) on has to look at the assembly Microsoft.SourceAnalysis.CSharp.Rules.dll.
The ones baked in are specifically:
And if you want to replace them with your own custom set, all you have to do is delete that particular dll – and design your own set. The code is very well structured, so it should not too hard to find your way around using Reflector. Enjoy.