-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCollectionBase.cs
More file actions
84 lines (49 loc) · 1.59 KB
/
CollectionBase.cs
File metadata and controls
84 lines (49 loc) · 1.59 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
using Gsemac.Collections.Extensions;
using System;
using System.Collections;
using System.Collections.Generic;
namespace Gsemac.Collections {
public abstract class CollectionBase<T> :
ICollection<T> {
// Public members
public int Count => Items.Count;
public bool IsReadOnly => Items.IsReadOnly;
public virtual void Add(T item) {
Items.Add(item);
}
public virtual bool Remove(T item) {
return Items.Remove(item);
}
public virtual void Clear() {
Items.Clear();
}
public bool Contains(T item) {
return Items.Contains(item);
}
public void CopyTo(T[] array, int arrayIndex) {
Items.CopyTo(array, arrayIndex);
}
public IEnumerator<T> GetEnumerator() {
return Items.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator() {
return Items.GetEnumerator();
}
// Protected members
protected ICollection<T> Items { get; }
protected CollectionBase() {
Items = new List<T>();
}
protected CollectionBase(ICollection<T> baseCollection) {
if (baseCollection is null)
throw new ArgumentNullException(nameof(baseCollection));
Items = baseCollection;
}
protected CollectionBase(IEnumerable<T> items) :
this() {
if (items is null)
throw new ArgumentNullException(nameof(items));
Items.AddRange(items);
}
}
}