using System; using System.Collections; using System.Collections.Generic; namespace ScreenConnect; public class DisposableList : List, IDisposableList, IList, ICollection, IEnumerable, IEnumerable, IDisposable where T : IDisposable { public DisposableList() { } public DisposableList(IEnumerable collection) : base(collection) { } public void Dispose() { Exception ex = null; using (Enumerator enumerator = GetEnumerator()) { while (enumerator.MoveNext()) { T current = enumerator.Current; if (current != null) { try { current.Dispose(); } catch (Exception ex2) { ex = ex2; } } } } if (ex != null) { throw ex; } } }