-
Notifications
You must be signed in to change notification settings - Fork 1
/
ReadOnlyList.cs
160 lines (145 loc) · 4.79 KB
/
ReadOnlyList.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
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Text;
namespace LogViewer
{
/// <summary>
/// Read-only wrapper around the generic IList class.
/// </summary>
/// <typeparam name="T">Type of object in the list.</typeparam>
[SuppressMessage("Microsoft.Naming", "CA1710")]
public class ReadOnlyList<T> : IList<T>
{
/// <summary>
/// The underlying list
/// </summary>
private IList<T> list;
/// <summary>
/// Creates a ReadOnlyList based on the given list.
/// </summary>
/// <param name="source">An IList of whatever.</param>
public ReadOnlyList(IList<T> source)
{
this.list = source;
}
/// <summary>
/// Returns the index of the given item.
/// </summary>
/// <param name="item">An item in the list.</param>
/// <returns>The index of the given item.</returns>
public int IndexOf(T item)
{
return this.list.IndexOf(item);
}
/// <summary>
/// Throws.
/// </summary>
/// <param name="index">Don't bother.</param>
/// <param name="item">Really, don't.</param>
/// <exception cref="InvalidOperationException">Every time.</exception>
public void Insert(int index, T item)
{
throw new InvalidOperationException();
}
/// <summary>
/// Throws.
/// </summary>
/// <param name="item">Just don't.</param>
/// <exception cref="InvalidOperationException">Every time.</exception>
public void RemoveAt(int index)
{
throw new InvalidOperationException();
}
/// <summary>
/// Gets an item at the given index. Don't try to set.
/// </summary>
/// <param name="item">The index of an item in the list.</param>
/// <exception cref="InvalidOperationException">If you try to set.</exception>
public T this[int index]
{
get
{
return this.list[index];
}
set
{
throw new InvalidOperationException();
}
}
/// <summary>
/// Throws.
/// </summary>
/// <param name="item">Just don't.</param>
/// <exception cref="InvalidOperationException">Every time.</exception>
public void Add(T item)
{
throw new InvalidOperationException();
}
/// <summary>
/// Throws.
/// </summary>
/// <exception cref="InvalidOperationException">Every time.</exception>
public void Clear()
{
throw new InvalidOperationException();
}
/// <summary>
/// Indicates whether the list contains the given item.
/// </summary>
/// <param name="item">An item that might be in the list.</param>
/// <returns>True if the item is in the list, false if not.</returns>
public bool Contains(T item)
{
return this.list.Contains(item);
}
/// <summary>
/// Copies the list to the given array.
/// </summary>
/// <param name="array">This should probably be an IList.</param>
/// <param name="arrayIndex">Where to begin copying items to.</param>
public void CopyTo(T[] array, int arrayIndex)
{
this.list.CopyTo(array, arrayIndex);
}
/// <summary>
/// Returns the size of the list.
/// </summary>
public int Count
{
get { return this.list.Count; }
}
/// <summary>
/// True.
/// </summary>
public bool IsReadOnly
{
get { return true; }
}
/// <summary>
/// Throws.
/// </summary>
/// <param name="item">Just don't.</param>
/// <exception cref="InvalidOperationException">Every time.</exception>
public bool Remove(T item)
{
throw new InvalidOperationException();
}
/// <summary>
/// Gets an enumerator for the list.
/// </summary>
/// <returns>An enumerator for the list.</returns>
public IEnumerator<T> GetEnumerator()
{
return this.list.GetEnumerator();
}
/// <summary>
/// Gets an enumerator for the list.
/// </summary>
/// <returns>An enumerator for the list.</returns>
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
return this.list.GetEnumerator();
}
}
}