[英]Is CA1001: TypesThatOwnDisposableFieldsShouldBeDisposable Valid?
If I have the following code: 如果我有以下代码:
public class Foo
{
public void Bar()
{
var someTypeWithAnEvent = new SomeTypeWithAnEvent();
using (var signal = new ManualResetEvent(false))
{
someTypeWithAnEvent.Begun += (sender, e) => signal.Set();
someTypeWithAnEvent.Begin();
signal.WaitOne();
}
}
}
FxCop seems to throw a CA1001 error: FxCop似乎抛出CA1001错误:
CA1001 : Microsoft.Design : Implement IDisposable on 'Foo' because it creates members of the following IDisposable types: 'ManualResetEvent'.
CA1001:Microsoft.Design:在'Foo'上实现IDisposable,因为它创建了以下IDisposable类型的成员:'ManualResetEvent'。
This doesn't seem valid in this instance because I'm disposing of the ManualResetEvent
through the using
block. 这在这个实例中似乎没有用,因为我通过
using
块处理了ManualResetEvent
。
Am I missing something here or is there an error in the rule? 我在这里遗漏了什么或者规则中有错误吗?
Let me guess: you're accessing signal in a lambda expression and the '..' in the error message is a compiler generated class. 让我猜一下:你正在访问lambda表达式中的信号,错误消息中的“..”是编译器生成的类。 In this case it's safe to suppress the message.
在这种情况下,可以安全地抑制消息。
根据这篇文章,这是一个已知的bug,因此应该保存以忽略错误。
I agree. 我同意。 This makes no sense - the signal will not survive undisposed.
这没有任何意义 - 信号不会无法生存。 Looks to me like an error in the parser (for the condition).
在我看来像解析器中的错误(对于条件)。 I would document it and put a pgragma into the file to supporess it.
我会记录它并在文件中放入一个pgragma来支持它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.