c# 问题 - 是否有一个工具可以确定我应该/可以在哪里使用“使用”确保资源关闭的声明?
c# 问题 - 有没有一种工具可以确定我应该/可以在哪里使用“using”语句来确保资源关闭? (以避免内存泄漏等)
包括以下两种情况:
a)有资源未关闭,
b)语法使用 try-catch-finally 并确定这可以更改为 using
谢谢
c# question - is there a tool to identify where I should/can use a "using" statement to ensure resources are closed? (to avoid memory leaks etc)
Including both the cases that:
a) there are resources not been closed and
b) syntax is using a try-catch-finally and identies this could be changed to a using
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我不确定它是否明确涵盖了情况 b,但是 Gendarme 是一个很好的工具,可以告诉您当您没有
using
语句时 围绕一次性物品。I'm not sure if it covers case b explicitly, but Gendarme is a fine tool that will tell you when you don't have a
using
statement around disposable objects.不知道这是否是您正在寻找的工具,但是 当您拥有实现 IDisposable 的类中的对象并且您没有处置它时,Code Rush 将突出显示您的代码。
Don't know if this is the kind of tool that you're looking for, but Code Rush will highlight your code when you have an object from a class that implements IDisposable and you're not diposing it.
查看是否可以在项目中启用代码分析并打开
Microsoft.Reliability:在失去范围之前释放对象
规则Take a look if you can to enable code analysis in your project and turn on
Microsoft.Reliability: Dispose objects before losing scope
ruleFxCop 是 Microsoft 提供的一款免费工具,可以执行此操作。它还包含在 Visual Studio 2005+ 的“团队系统”变体中
FxCop is a free tool from Microsoft that can do this. It's also included in the "Team System" variants of Visual Studio 2005+