This project is read-only.

Skip methods that are marked as Obsolete

Dec 22, 2010 at 12:12 PM

I'm using StyleCop to clean up some old but still used code.
This code has had many developers so several styles are used.

When I have a public method that starts with a lower-case character I copy that method, make the name correctly and let the old method call the new method.
I also mark the old method as being deprecated:   [Obsolete("This method is obsolete; use GetConversionFactor() instead")]
This way I retain backwards compatibility and over time I can update the classes that are using these methods.

This works fine, but StyleCop keeps complaining with 'SA1300: method names begin with an upper-case letter'.

Wouldn't it make sense that StyleCop would skip checking methods that are marked as obsolete?

Dec 25, 2010 at 7:31 PM

I think StyleCop works absolutely correct here.

It already has "SuppressMesssage" attribute for skipping checking - why to have another one?
Moreover, someone else could want to have obsolete methods checked.

In your case, you could mark methods with "SuppressMessage" attribute instead of (or together with) "Obsolete" one.

What do you think?

Best regards,
Oleg Shuruev

Dec 28, 2010 at 9:02 PM

You're right.

I didn't think of "SuppressMessage"

Using these lines works:

[SuppressMessage("Microsoft.StyleCop.CSharp.NamingRules", "SA1300:ElementMustBeginWithUpperCaseLetter", Justification = "This method is obsolete")]
[SuppressMessage("Microsoft.StyleCop.CSharp.DocumentationRules", "SA1600:ElementsMustBeDocumented", Justification = "This method is obsolete")]