-
-
Notifications
You must be signed in to change notification settings - Fork 892
Expand file tree
/
Copy pathDisposableList.cs
More file actions
51 lines (44 loc) · 1.21 KB
/
DisposableList.cs
File metadata and controls
51 lines (44 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.Common.Helpers;
/// <summary>
/// List of <see cref="IDisposable"/> objects, which is itself <see cref="IDisposable"/>.
/// </summary>
/// <typeparam name="TValue">Tye type of value, needs to implement <see cref="IDisposable"/>.</typeparam>
public sealed class DisposableList<TValue> : List<TValue>, IDisposable
where TValue : IDisposable
{
private bool disposedValue;
/// <inheritdoc />
public DisposableList()
: base()
{
}
/// <inheritdoc />
public DisposableList(int capacity)
: base(capacity)
{
}
/// <inheritdoc />
public void Dispose()
{
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
this.Dispose(disposing: true);
GC.SuppressFinalize(this);
}
private void Dispose(bool disposing)
{
if (!this.disposedValue)
{
if (disposing)
{
foreach (TValue item in this)
{
item?.Dispose();
}
}
this.Clear();
this.disposedValue = true;
}
}
}