I have a non static class that deals with some unmanaged code, my class inherits IDisposable which requires that the class implements the Dispose() method. How can I make this require Dispose() is called on an instance of this class, not just implemented in the class itself?
public class MyClass : IDisposable
{
//Some fields and methods
public void Dispose()
{
//Code that frees unmanaged resourses
}
}
In my main method:
public void main()
{
var myClassInstance = new MyClass();
//Some code that does stuff with myClassInstance
//I forget here to call myClassInstance.Dispose();
}
I now want to be given a warning. For Example: "You have not called Dispose on myClassInstance".