VS 2010 snippets vs Stylecop

Feb 21, 2011 at 12:52 PM

VS 2010 contains various snippets (like propdp) which violate standard Stylecop rules. For example, Propdp creates something like this:

/// <summary>
/// Using a DependencyProperty as the backing store for MyProperty.  This enables animation, styling, binding, etc...
/// </summary>
public static readonly DependencyProperty MyPropertyProperty = 
                 
DependencyProperty.Register("MyProperty"typeof(int), typeof(MainWindow), 
                  new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.AffectsMeasure, 
                 
new PropertyChangedCallback(OnMyPropertyChanged)));

This violates rules SA1116 and SA1118. And of course, it is hard to read.
To fix the warnings, you could reformat like this (which may also be hard to read because of the potentially very long last line we are not allowed to break):

/// <summary>
/// Using a DependencyProperty as the backing store for MyProperty.  This enables animation, styling, binding, etc...
/// </summary>
public static readonly DependencyProperty MyPropertyProperty = DependencyProperty.Register(
            "MyProperty"
            typeof(int), 
            typeof(MainWindow), 
            new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.AffectsMeasure, new PropertyChangedCallback(OnMyPropertyChanged)));

The only other option I can think of is using a static method which contains the DependencyProperty.Register call.
However, having to reformat standard snippets is an effort which is hard to communicate. But I also don't want to disable rules SA116 and SA118.
Any ideas how to handle this?

 

Feb 21, 2011 at 2:51 PM

hi goetzman

Take a look at the following project: http://vssnippets.codeplex.com/

It provides stylecop compliant code snippets that replace all the built in code snippets.

 

Hope this helps.

Marco