Can I force the use of the 'using' statement for instances of my IDisposable class?

If my class (which in this case, takes care of database connections) implements IDisposable, is there a way I can force the use of of the using statement when instantiating my class? Or perhaps produce a compiler warning if this wasn't done?

eg:

MyDAL = new MyDal(); // Warns or errors
using (MyDAL = new MyDAL()) // Does not warn or error
Jon Skeet
people
quotationmark

No, there's no language level support for this.

However, you may find that tools such as FxCop or ReSharper can warn about it. (You'd need to work out how to integrate that into your workflow.)

people

See more on this question at Stackoverflow