Is there any nice pattern in .Net for ensuring that iDisposable fields owned by an object will get disposed if an exception is thrown during construction, possibly during a field initializer? The only way to surround field initializers in a Try/Catch block is if the block is outside the call to the constructor, which will make it rather difficult for cleanup code to properly dispose of anything.
The only approach I can figure would be to the object inherit from a base class whose constructor takes something like an array of iDisposable, and sets the first item in that array to point to itself. All constructors the descendant classes should be Private or Orotected, and include that parameter. Instantiation should be via factory methods, which will declare an array of one iDisposable and pass it to the appropriate constructor. If the constructor fails, the factory method will have a reference to the partially-constructed object, which it can then dispose (the dispose method must, of course, be prepared to accept the possibility that the object may not be fully constructed).
The approach could be extended by having the object keep a list of iDisposable objects it creates, to allow the objects to be cleaned up without having to explicitly dispose each one; such a list would be useful in conjunction with the factory-method-calls-dispose approach, but is largely orthogonal to it.
Any thoughts?