可以ReSharper的设置,如果IDisposable的处理不正确警告? [英] Can Resharper be set to warn if IDisposable not handled correctly?

查看:240
本文介绍了可以ReSharper的设置,如果IDisposable的处理不正确警告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有ReSharper的4档(甚至是Visual Studio的本身......),迫使一个警告,如果我忘了包装在一个使用块code或ommit在适当的处置呼叫最后阻止?

Is there a setting in Resharper 4 (or even Visual Studio itself...) that forces a warning if I forget to wrap code in a using block, or ommit the proper Dispose call in a finally block?

推荐答案

正确的自动处置分析需要DFA(数据流分析)在全球的方式。这是不可能的,你创建一个IDisposable的对象,不调用它的任何方法,并没有通过它周围作为参数。如果一次性对象传递给其他方法(包括调用它的成员,当这个隐式传递),该工具应分析是否处置不中调用,或对象不进行存储供以后处理。

Correct automatic Dispose analysis requires DFA (Data Flow Analysis) in a global way. It is unlikely that you create an IDisposable object and doesn't call any method on it and do not pass it around as an argument. If disposable object is passed to other methods (including calling its members, when "this" is implicitly passed), the tool should analyse if Dispose is not called within, or that object is not stored somewhere for later disposal.

这就是说,幼稚执行检查,如果一次性目的是在设置了使用构造或以任何其他方式将产生太多假阳性,并呈现分析无用的事实。

That said, naive implementation of checking if disposable object is in fact disposed with "using" construct or in any other way would yield too much false positives, and render analysis useless.

这篇关于可以ReSharper的设置,如果IDisposable的处理不正确警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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