从.Designer.cs文件禁用/修复代码分析警告 [英] Disabling/Fixing Code Analysis warnings from .Designer.cs files

查看:68
本文介绍了从.Designer.cs文件禁用/修复代码分析警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在广泛使用DataVisualization.Charting.Chart,并且在大多数情况下都可以使用.但是,我经常运行代码分析,并处理了所有我自己的警告.但是,在使用图表的* .Designer.cs文件中,大约有30个CA2000(对象未沿所有异常路径放置). Designer文件正在生成几乎所有图表代码,并且几乎所有图表元素都实现IDisposable.我在项目首选项中选中了禁止从生成的代码中获取结果",但仍然可以.

I am using DataVisualization.Charting.Chart extensively, and for the most part it is working. However, I've been running Code Analysis frequently, and have all my own warnings taken care of. But, there are about 30 CA2000 (object not disposed along all exception paths) in the *.Designer.cs files that use the charting. The Designer files are generating pretty much all the charting code, and almost all the charting elements implement IDisposable. I have "Suppress results from generated code" checked in the project preferences, but it still does it.

是否有任何方法可以解决此问题,而不必手动创建图表对象,也不必为该类中的其余代码禁用代码分析?有没有一种方法可以禁用所有.Designer.cs文件?或者,是否存在一种解决方案,可以通过使设计者代码得到妥善处理来正确删除这些警告?

Is there any way to fix this, without having to manually create the chart objects, and without disabling Code Analysis for the rest of the code in that class? Is there a way to disable it for all .Designer.cs files? Or, is there a solution to remove these warnings correctly by making the designer code take care of disposal?

推荐答案

相当少的开发人员似乎碰巧遇到了这种情况,因此+1是一个很好的问题!

A fair few developers appear to have encountered this without a luck, so +1 for a good question!

一种可行的解决方案是编写一个重写CA2000并抑制规则的方法,如果在设计器文件中检测到警告,则这是一个很好的开始:

A possible solution is to write a method that override's CA2000 and suppresses the rule if the warning is detected in a designer file, here's a good start:

否则,请参阅本主题末尾的注释,MSFT工程师提到记录一次Connect调用:

Otherwise see the comments at the end of this thread, MSFT engineers mention to log a Connect call: http://blogs.msdn.com/b/codeanalysis/archive/2010/03/22/what-s-new-in-code-analysis-for-visual-studio-2010.aspx

这篇关于从.Designer.cs文件禁用/修复代码分析警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆