Supressing VS2005 Code Analysis Messages

I was going through our code here and started to ‘clean’ it up.  As I was doing this, I was noticing that the naming rule CA1705 was saying that I should rename some of my property names based on an acronym that was in ALL caps such as APR (annual percentage rate).  While there is some debate amongst the team as to whether or not to follow the rule, until we figure it out, I have found a way to temporarily suppress the message on that particular proper. 

The solution? System.Diagnostics.CodeAnalysis.SuppressMessage.  This is an attribute that you can place on any member in a file.  Once applied it will suppress any messages for the configured member.  Here is how I implemented the attribute for the rule that was giving me a problem:

[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1705:LongAcronymsShouldBePascalCased")]

The first parameter is the name of the category that has the rule is in.  The second is the check id and the name of the rule, delimited by a “:“. 

An alternate way is to use the IDE to do it by right clicking on the warning and choosing to ‘Suppress Message(s)” which will add the attribute for you.

You can read more about both mechanisms here on MSDN.

Published Monday, June 05, 2006 11:40 PM by dotnetgeek
Powered by Community Server (Non-Commercial Edition), by Telligent Systems