IDS peak ICV v1.3.0
Loading...
Searching...
No Matches
DisposableList.cs
Go to the documentation of this file.
2
8public class DisposableList<T> : List<T>, IDisposable where T : IDisposable
9{
10 private bool _disposed;
11
16 public DisposableList(List<T> list) : base(list)
17 {
18 }
19
25 {
26 }
27
32 public void Dispose()
33 {
34 if (_disposed)
35 {
36 return;
37 }
38
39 foreach (T? disposable in this)
40 {
41 disposable.Dispose();
42 }
43
44 _disposed = true;
45 GC.SuppressFinalize(this);
46 }
47
53 {
54 Dispose();
55 }
56}
A list that automatically calls IDisposable.Dispose on all its elements when disposed.
DisposableList(List< T > list)
Creates a new instance of DisposableList<T> with an existing list.
void Dispose()
Disposes all elements.
DisposableList()
Creates an empty instance of DisposableList<T>.