| 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 |
using System; |
| 30 |
using System.Collections; |
| 31 |
using System .Collections.Generic; |
| 32 |
|
| 33 |
namespace Mono.Collections.Generic { |
| 34 |
|
| 35 |
public sealed class ReadOnlyCollection<T> : Collection<T>, ICollection<T>, IList { |
| 36 |
|
| 37 |
static ReadOnlyCollection<T> empty; |
| 38 |
|
| 39 |
public static ReadOnlyCollection<T> Empty { |
| 40 |
get { return empty ?? (empty = new ReadOnlyCollection<T> ()); } |
| 41 |
} |
| 42 |
|
| 43 |
bool ICollection<T>.IsReadOnly { |
| 44 |
get { return true; } |
| 45 |
} |
| 46 |
|
| 47 |
bool IList.IsFixedSize { |
| 48 |
get { return true; } |
| 49 |
} |
| 50 |
|
| 51 |
bool IList.IsReadOnly { |
| 52 |
get { return true; } |
| 53 |
} |
| 54 |
|
| 55 |
private ReadOnlyCollection () |
| 56 |
{ |
| 57 |
} |
| 58 |
|
| 59 |
public ReadOnlyCollection (T [] array) |
| 60 |
{ |
| 61 |
if (array == null) |
| 62 |
throw new ArgumentNullException (); |
| 63 |
|
| 64 |
Initialize (array, array.Length); |
| 65 |
} |
| 66 |
|
| 67 |
public ReadOnlyCollection (Collection<T> collection) |
| 68 |
{ |
| 69 |
if (collection == null) |
| 70 |
throw new ArgumentNullException (); |
| 71 |
|
| 72 |
Initialize (collection.items, collection.size); |
| 73 |
} |
| 74 |
|
| 75 |
void Initialize (T [] items, int size) |
| 76 |
{ |
| 77 |
this.items = new T [size]; |
| 78 |
Array.Copy (items, 0, this.items, 0, size); |
| 79 |
this.size = size; |
| 80 |
} |
| 81 |
|
| 82 |
internal override void Grow (int desired) |
| 83 |
{ |
| 84 |
throw new InvalidOperationException (); |
| 85 |
} |
| 86 |
|
| 87 |
protected override void OnAdd (T item, int index) |
| 88 |
{ |
| 89 |
throw new InvalidOperationException (); |
| 90 |
} |
| 91 |
|
| 92 |
protected override void OnClear () |
| 93 |
{ |
| 94 |
throw new InvalidOperationException (); |
| 95 |
} |
| 96 |
|
| 97 |
protected override void OnInsert (T item, int index) |
| 98 |
{ |
| 99 |
throw new InvalidOperationException (); |
| 100 |
} |
| 101 |
|
| 102 |
protected override void OnRemove (T item, int index) |
| 103 |
{ |
| 104 |
throw new InvalidOperationException (); |
| 105 |
} |
| 106 |
|
| 107 |
protected override void OnSet (T item, int index) |
| 108 |
{ |
| 109 |
throw new InvalidOperationException (); |
| 110 |
} |
| 111 |
} |
| 112 |
} |