简体   繁体   English

UserControls中的FxCop CA2000警告

[英]FxCop CA2000 Warning in UserControls

Running FxCop on a WebProject that contains a UserControl will result in a CA2000 Warning (Call System.IDisposable.Dispose on object) for every ServerControl (Label, TextBox,...) in that UserControl. 在包含UserControl的Web项目上运行FxCop将导致该UserControl中的每个ServerControl(标签,文本框等)出现CA2000警告(在对象上调用System.IDisposable.Dispose)。

I understand why this would happen. 我知道为什么会这样。
Replacing the 'offending' ServerControls with a PlaceHolder and then adding the Controls in code (Using...End Using) might be a way around that, but it is not always an option. 用PlaceHolder替换“有问题的” ServerControl,然后在代码中添加控件(使用...最终使用)可能是解决此问题的方法,但并非总是这样。
But, if they are not 'kosher' why have ServerControls you can drop in your ascx/aspx in the first place ? 但是,如果它们不是“洁净的”,为什么首先要有ServerControls可以放入ascx / aspx?
Am I missing something ? 我想念什么吗?

If, like in my case, you inherit a sizeable collection of fairly complex UserControls, do I now add every 'offending' Control to the GlobalSupperssions file (that's a lot of mind numbing right-clicking) ? 如果像我这样,您继承了相当大数量的相当复杂的UserControls集合,那么我现在是否将每个“有问题的”控件添加到GlobalSupperssions文件中(这很容易使您右键单击)。
I do not want to suppress all CA2000 warnings since it makes perfect sense to fix them, but not in the case of ServerControls in UserControls. 我不想抑制所有CA2000警告,因为修正它们很有意义,但对于UserControls中的ServerControls而言,并不是这样。

Hmya, everybody really likes a tool that will tell them that they forgot to call Dispose(). 嗯,每个人都非常喜欢一个可以告诉他们他们忘记调用Dispose()的工具。 Problem is: such a tool is really hard to implement. 问题是:这样的工具确实很难实现。 The specific warning you are talking about got disabled and re-enabled a few times now. 您正在谈论的特定警告已被禁用并重新启用了几次。

Obviously the warning you got is nonsense, a UserControl already knows how to properly dispose its member controls. 显然,您得到的警告是胡说八道,UserControl已经知道如何正确处理其成员控件。 It is just not something that an automated tool can easily detect. 自动化工具无法轻松检测到它。 The dispose call is a million miles removed from the constructor call, buried in .NET framework code with a couple of virtual methods and event handlers thrown in the mix. Dispose调用与构造函数调用相距100万英里,它被埋在.NET Framework代码中,并带有两个虚拟方法和事件处理程序。

To really evaluate those warnings, you'll have to switch to another tool: the one between your ears. 真正评估这些警告,您必须切换到另一种工具:耳朵之间的工具。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM