How do I ignore a specific VS code analysis rule (say CA1305 : Microsoft.Globalization) within a:
- Method?
- Class?
- Namespace?
(Assuming these options are all possible.)
How do I ignore a specific VS code analysis rule (say CA1305 : Microsoft.Globalization) within a:
(Assuming these options are all possible.)
Use #pragma warning(suppress: Cxxxx)
You can put the pragma at the appropriate scope in the source file (i.e. class, method)
See http://msdn.microsoft.com/en-us/library/2c8f766e(VS.80).aspx
You can use the SupressMessage attribute like this:-
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2233:OperationsShouldNotOverflow", MessageId = "newValue+1", Justification = "The reason I think its acceptable in this case")]
void SomeMethod()
{
// Some code that would normal cause this Code Analysis message
}
On a method, property, type etc.
I downloaded FXCop as suggested by @TrueWill's comment on @AnthonyWJones' answer. This gave me the SuppressMessage:
[SuppressMessage("Microsoft.Globalization",
"CA1305:SpecifyIFormatProvider",
MessageId = "System.String.Format(System.String,System.Object)")]
This was far harder than it should have been. What happened to that FXCop integration into Visual Studio? Thanks to the answerers for their help.