It is recommended that you do this anytime a class implements the IDisposable
". Unfortunately the compiler and Visual Studio do not guarantee this. I even understand that the compiler does not enforce because there are rare legitimate cases that you should not use this form.
But an additional configurable tool should help. Fortunately there is the Resharper that can alert you that whenever the class you are instantiating is not in a using
. It's the only way I know it, but other competing plugins should have something similar. Obviously the alert is only made for classes that implement IDisposable
.
You can also customize the new .Net Compiler Platform to do this. I do not have data to tell how to do this and it should not be too trivial, though it may not be too complex either. The idea of the new compiler platform is just to let people extend their operation as needed.