in

Dé specialist in .NET trainingen en consultancy

Erik van Appeldoorn

maart 2009 - Posts

  • Microsoft StyleCop settings

    I really like Microsoft StyleCop formerly known as Microsoft Source Analysis to check my C# code against a fixed set of style rules and conventions. Using a tool like StyleCop makes your code writing consistent and easier to read, not only for yourself but maybe even more important for your colleagues as well.

    StyleCop integrates nicely into Visual Studio. Just press [Control-Shift-Y] to start rule validation. Violations appear as warnings in the Visual Studio error list.

    image

     

    Yes, setting explicit access modifiers is a good thing. Maybe Microsoft should consider adding explicit access modifiers in their templates as well ;)

    StyleCop applies rules settings on a per project basis. So every project will get a Settings.StyleCop file which defines the rules to apply on the project. By right-clicking the project in VS and select StyleCop settings you can determine which rules to apply on the project.

     

    image

    In this example I have deselected all the Documentation Rules. You can select/deselect individually rules as well.

     

    There is also a Settings.StyleCop file in the installation directory of StyleCop. Changes made in this file will apply to all projects and can be overridden locally. To edit this file select the uppermost edit.. button at the Settings Files tab.

    image

    More information on StyleCop and the free download link can be found at http://blogs.msdn.com/sourceanalysis/