Resharper custom search pattern to warn IDisposable objects

旧城冷巷雨未停 提交于 2019-11-29 12:18:09

The problem with these patterns is that they don't go away when you actually dispose the object, except may be for local variable declarations inside using statements. It also doesn't track object ownership, e.g. for factory methods and pass-through methods. So I believe making it through structured patterns is next to useless.

Anyway, you may need two patterns for local variable checks like

var $identifier$ = $expression$; 
$type$ $identifier$ = $expression$;

where expression and type are implementing IDisposable.

Steve Dunn

While this doesn't directly answer your question, there are various runtime techniques to find undisposed IDisposables. Here's one such technique.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!