Is this a good Dispose() idea or not?

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



use reflection to detect class and instance fields which require
disposal
you can derive from a base class with these methods and it will
automatically dispose

void IDisposable.Dispose() {
DisposeObject(this);
GC.SuppressFinalize(this);
}//method
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - -
static void DisposeObject(object instance) {
FieldInfo[] fis = instance.GetType().GetFields(BindingFlags.Instance |
BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
foreach (FieldInfo fi in fis) {
DisposeField(fi.GetValue(instance));
}//foreach
}//method
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - -
static void DisposeField(object o) {
if (o == null) return;
MethodBase mb = o.GetType().GetMethod("Dispose");
if (mb == null) return;
mb.Invoke(o, new object[] {});
}//method

.



Relevant Pages

  • Re: inhibit compiler warning C4624 for a class hierarchy
    ... I'd really like to just pretend that the dynamic type is the base class. ... ** Carries a request or notification and any associated parameters. ... static void* operator new ... struct PNPEXPORT IConcurrentOperations::OpNotification abstract: public ...
    (microsoft.public.vc.language)
  • Re: Hooking automation object Events
    ... The next few lines of my post show the procedure SelectionChange: ... _PowerPCBDocEvents = dispinterface; ... void PowerPCBSink::OnFinalRelease ... // object before calling the base class. ...
    (comp.lang.pascal.delphi.misc)
  • RE: Protected keyword
    ... Only the Employee class internally can see the base class RaiseEvent method. ... public void HoldBreath{ ... a child that inherits from it so as to be able to call the protected method ...
    (microsoft.public.dotnet.languages.csharp)
  • Threads
    ... base class and then at least 2 classes that extends Thread. ... void upDateScreen() ...
    (comp.lang.java.programmer)
  • Type of base pointer
    ... public override void Test() ... base class for B is A not A" ... I have a virtual function called Testin class A. Also i have class B ... As well base object doesn't have method OldTest(). ...
    (microsoft.public.dotnet.framework)