FXCOP抑制警告CA1800(不必要的演员)
-
29-09-2019 - |
题
我有以下代码:
[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
}
但是,当我跑步时 FxCop
在此类/功能上,它仍然会生成警告
警告:CA1800:Microsoft.performance:“表”,一个参数,被施放在方法'ccc.settestconnectionstring(component)'中多次键入'xxx'。缓存“ AS”操作员或直接铸造的结果,以消除冗余的CastClass指令。
我知道我可以重构此代码以删除警告,但是这会使代码不那么可读。在这种情况下,我想在此功能上抑制此一条消息。
我究竟做错了什么?
解决方案
检查您是否在项目属性中定义了预处理器符号code_analysis。
其他提示
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
}
我怀疑您的项目文件包含debugtype是没有的。设置debugtype无需时,它将不会检测到抑制代码。因此,您可以将debugtype更改为Full,因为它将正确检测抑制代码。
<DebugType>full</DebugType>
不隶属于 StackOverflow