// License: Apache 2.0. See LICENSE file in root directory. // Copyright(c) 2017 Intel Corporation. All Rights Reserved. namespace Intel.RealSense { using System; /// /// A container for disposing of multiple objects /// public interface ICompositeDisposable : IDisposable { /// /// Add an object to to be disposed along with this instance /// /// an to to be disposed along with this instance void AddDisposable(IDisposable disposable); } // https://leeoades.wordpress.com/2012/08/29/neat-disposal-pattern/ public static class DisposableExtensions { /// /// Generic extension method to help dispose of objects /// /// type implementing /// object to add to /// composite disposable container /// the object public static T DisposeWith(this T disposable, ICompositeDisposable composite) where T : class, IDisposable { if (disposable == null || composite == null) { return disposable; } composite.AddDisposable(disposable); return disposable; } } }