Understanding disposable objects
Understanding disposable objects |
What is a disposable object - I've looked in SO about a question like this one, and even that I've found quite a few, any of those threw any light into this matter for me.
Let's assume I have this code:
public class SuperObject : IDisposable
{
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing) { }
}
Do I need the protected virtual void Dispose(bool) on SuperObject? Since there is really nothing to dispose there.
public interface ICustom : IDisposable { }
public class Custom : ICustom
{
public SuperObject Super { get; protected set; }
public Custom()
{
Super = new SuperObject();
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
public virtual void Dispose(bool disposing)
{
if (!disposing) return;
if (Super != null)
Super.Dispose();
}
}
public class Foo
{
public Foo()
{
using (var c = new Custom())
{
//do magic with c
}
}
}
Now what happens if I want/need/try to use Custom on a class like System.Web.Mvc.Controller which already implements and has implemented IDisposable?
public class Moo : Controller
{
Custom c;
public Moo()
{
c = new Custom();
}
// Use c throughout this class
}
With the information we provide about What is a disposable object
, We hope you can be helped and hopefully set a precedent with you . Or also you can see our other references are also others which are not less good about MEN'S SHIRTS
, So and we thank you for visiting.
open tutorial sew : http://stackoverflow.com/questions/19076312/understanding-disposable-objects
0 komentar:
Post a Comment