FXCop Suppress Warning CA1800 (Unnecessary Roles)

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 FxCopon this class / function, it still generates a warning

warning: CA1800: Microsoft.Performance: 'table', parameter, is cast to type "xxx" several times in the method 'Ccc.SetTestConnectionString (Component)'. Cache the result of an "like" statement or direct casting to eliminate redundant instruction class.

I know that I can reorganize this code to remove the warning, however this will make the code less readable. In this case, I would like to suppress this one message on this one function.

What am I doing wrong?

+3
3
private static void SetTestConnectionString( Component table )
{
    if( table.GetType() == typeof(Object1) )
    {
        Object1 object1 = (Object1)table;
        fn1( object1 );
    }
    // ... a few more if statements for different Classes
}
0

I suspect your project file contains DebugType - no. If DebugType is set to none, it will not detect a suppression code. This way you can reverse the DebugType completely because it will correctly detect the suppression code.

<DebugType>full</DebugType>
0
source

Source: https://habr.com/ru/post/1760552/


All Articles