Thursday, April 23, 2009

How to convince FxCop to ignore "ID"

When you have properties like OrderID (with ID uppercase) FxCop treats it as naming rules' violation. I've been asked how to remove this error without manually excluding each occurrence.

Here is what FxCop stated:
"Resolution : "Correct the casing of 'ID' in member name 'Order.OrderID'
by changing it to 'Id'. 'Id' is an abbreviation and
therefore is not subject to acronym casing guidelines."
Help : http://msdn2.microsoft.com/library/ms182240(VS.90).aspx (String)
"

After looking into FxCop naming rules' details (using Reflector) I've found that "ID" is a hardcoded case (along with "Ok") and the only way to override is to add "ID" to casing exception in CustomDictionary.xml as:
<Acronyms>
<CasingExceptions>
<Acronym>ID</Acronym>
</CasingExceptions>
</Acronyms>