gpt4 book ai didi

c# - FXCop 抑制警告 CA1800(不必要的转换)

转载 作者:行者123 更新时间:2023-11-30 15:10:12 27 4
gpt4 key购买 nike

我有以下代码:

[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 时,它仍然会生成警告

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.

我知道我可以重构此代码以删除警告,但这会降低代码的可读性。在这种情况下,我想在这个函数上抑制这条消息。

我做错了什么?

最佳答案

检查您是否在项目属性中定义了预处理器符号 CODE_ANALYSIS。

看看:http://msdn.microsoft.com/en-us/library/system.diagnostics.codeanalysis.suppressmessageattribute.aspx

关于c# - FXCop 抑制警告 CA1800(不必要的转换),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3522612/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com