DisposeAll - Yortw/Yort.Trashy GitHub Wiki
DisposeAssistant.DisposeAll is used to dispose multiple objects in a single call. While the TryDispose extension method can be used to dispose many objects in a collection, DisposeAll allows passing each object as it's own parameter.
// Disposes disposable1, disposable2, and disposable3 independently in a single call.
// The dispose is performed using [TryDispose](/Yortw/Yort.Trashy/wiki/TryDispose) so null references/references that don't
// implement IDisposable are handled quietly.
DisposeAssistant.DisposeAll(disposable1, disposable2, disposable3);
A second overload exists allowing you to specify options for disposal;
// Disposes disposable1, disposable2, and disposable3 independently in a single call.
// The dispose is performed using [TryDispose](/Yortw/Yort.Trashy/wiki/TryDispose) so null references/references that don't
// implement IDisposable are handled quietly. Using the SuppressExceptions option
// means any errors from the dispose methods will be suppressed.
DisposeAssistant.DisposeAll(DisposeOptions.SuppressExceptions, disposable1, disposable2, disposable3);
If any errors occur during dispose and DisposeOptions.SuppressExceptions was not specified, a System.AggregateException is thrown containing each inner exception.