Question

I always tend to group all stuff that belongs to a dependency property (registration, clr property, change callback, coerce callback etc.) into one region. But this violates the stylecop member ordering rules. This is also a general problem with codesnippets that generate multiple members, since the snippets can not generate code at different places in my file. What is you philosophy on this? Do you disbale the stylecop rules or do you put everything at its "right" place?

Also I personally think that stylcop should not complain about this:

/// <summary>
/// RepeatX Dependency Property
/// </summary>
public static readonly DependencyProperty RepeatXProperty =
    DependencyProperty.Register(
        "RepeatX", 
        typeof(int), 
        typeof(GeometryViewbox), 
        new FrameworkPropertyMetadata
            {
                DefaultValue = 1, 
                AffectsRender = true, 
                AffectsParentMeasure = true, 
                PropertyChangedCallback = OnRepeatXChanged, 
                CoerceValueCallback = CoerceRepeatXValue
            });

Stylcop should generate addtional work for us to do. In the above example sticking to stylcecop makes you less productive plus the code becomes less readable, because you are forced to put the above code in the static ctor (instead of field initialization) to be able to make FrameworkPropertyMetadata into a temp variable. One additional temp variable for each dependency property doesn't make the code more readable/maintainable plus you can't use codesnippets anymore.

Was it helpful?

Solution

In the above example sticking to stylcecop makes you less productive plus the code becomes less readable

If you truly believe that then don't use it. No-one is forcing you to use it, just like no-one is forcing you to stop using Hungarian notation if you want to. If you're a lone developer and no-one will see your source code then format it however makes you happy, you're the person that has to maintain it. If you're in a larger team then you should get some coding standards in place so you can read each other's code easily - but you don't have to use stylecop for that if you don't want to.

Just because a tool is available doesn't mean it's going to suit your needs and you must use it. You are allowed to think for yourself.

OTHER TIPS

We tend to put everything as Stylecop suggests. It's just easier that way. Less hassle. And if you follow the rules in all cases, you always know where to look for things. Besides, you can use that drop down menu to jump straight to member declarations.

FWIW, we also never use regions. Things are less cluttered that way.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top