/
LinkedResourceCollection.cs
58 lines (48 loc) · 1.51 KB
/
LinkedResourceCollection.cs
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
52
53
54
55
56
57
58
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
using System.Collections.ObjectModel;
namespace System.Net.Mail
{
public sealed class LinkedResourceCollection : Collection<LinkedResource>, IDisposable
{
private bool _disposed;
internal LinkedResourceCollection()
{ }
public void Dispose()
{
if (_disposed)
{
return;
}
foreach (LinkedResource resource in this)
{
resource.Dispose();
}
Clear();
_disposed = true;
}
protected override void RemoveItem(int index)
{
ObjectDisposedException.ThrowIf(_disposed, this);
base.RemoveItem(index);
}
protected override void ClearItems()
{
ObjectDisposedException.ThrowIf(_disposed, this);
base.ClearItems();
}
protected override void SetItem(int index, LinkedResource item)
{
ObjectDisposedException.ThrowIf(_disposed, this);
ArgumentNullException.ThrowIfNull(item);
base.SetItem(index, item);
}
protected override void InsertItem(int index, LinkedResource item)
{
ObjectDisposedException.ThrowIf(_disposed, this);
ArgumentNullException.ThrowIfNull(item);
base.InsertItem(index, item);
}
}
}