I have the following code:
[SuppressMessage( "Microsoft.Performance", "CA1800:DoNotCastUnnecessarily" )]
private static void SetTestConnectionString( Component table )
{
if( table is Object1 )
{
fn1( (Object1)table );
}
// ... a few more if statements for different Classes
}
However, when I run FxCop over this Class/Function it still generates the Warning " warning : CA1800 : Microsoft.Performance : 'table', a parameter, is cast to type 'xxx' multiple times in method 'ccc.SetTestConnectionString(Component)'. Cache the result of the 'as' operator or direct cast in order to eliminate the redundant castclass instruction.
I know I could refactor this code to remove the warning, however it would make the code less readable. In this instance I would like to suppress this one message on this one function. What am I doing wrong?!