Earlier today I did a code maintenance session on BlogEngine.NET using the excellent FxCop tool. It was a while since I’ve did so there were quite a few things to correct in the code. I actually like spending time with FxCop and fixing the broken rules. There’s something very relaxing about it. Even though FxCop is excellent, it is not without its quirks.

Compound words should be cased correctly

Based on this rule, FxCop told me to correct the spelling of Whitespace to WhiteSpace. I didn’t think more about it and just accepted that whitespace probably isn’t one word but two. After the change I ran FxCop again and, lo and behold, it suggested that I should change WhiteSpace back to Whitespace. Hmm, thought I just did the opposite because it broke the rule.

Avoid namespaces with few types

This rule makes sense if you only have a single class in a namespace, but it breaks if you have fewer than 5 types. Now here is the thing. I have a namespace with only four types and I want it that way. Stop telling me that I shouldn’t!

Do not pass literals as localized parameters

This rule is a globalization rule that breaks if you write the content of a string manually in the source files instead of putting them in resource files. When I throw some exceptions or construct some strings that I know will not be localized then I couldn’t care less about this rule. If I were to put every string in a resource file, it would be hard to work with. I turned the rule off.

Do not declare static members on generic types

In English: Don’t write a static method or property that uses Generics in its declaration. The rule also states that you must never exclude that rule no matter what. It states that in order to call that method you need to write bad code such as

someObject.GenericMethod<int>();

Well, that is not correct. You can have a static member using Generics without calling it with the <type> syntax if you know how to write the members correctly. Apparently it doesn’t take smart people into account for this one.

Conclusion

Even though this post sounds a bit negative I’m still a big fan of FxCop. Some of these rules are perfectly fine to break according for some scenarios. The rules state that them selves. These few ones have just annoyed me ever since I started using FxCop a couple of years ago.

Comments


Comments are closed