blob: 70103022f252930ea40795961c7a2c6d65e61fe5 (
plain) (
blame)
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
|
using System;
using System.Collections;
using System.Collections.Generic;
namespace Org.BouncyCastle.Utilities.Collections
{
internal abstract class ReadOnlyList<T>
: IList<T>
{
public T this[int index]
{
get { return Lookup(index); }
set { throw new NotSupportedException(); }
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
public bool IsReadOnly => true;
public void Add(T item) => throw new NotSupportedException();
public void Clear() => throw new NotSupportedException();
public void Insert(int index, T item) => throw new NotSupportedException();
public bool Remove(T item) => throw new NotSupportedException();
public void RemoveAt(int index) => throw new NotSupportedException();
public abstract int Count { get; }
public abstract bool Contains(T item);
public abstract void CopyTo(T[] array, int arrayIndex);
public abstract IEnumerator<T> GetEnumerator();
public abstract int IndexOf(T item);
protected abstract T Lookup(int index);
}
internal class ReadOnlyListProxy<T>
: ReadOnlyList<T>
{
private readonly IList<T> m_target;
internal ReadOnlyListProxy(IList<T> target)
{
m_target = target;
}
public override int Count => m_target.Count;
public override bool Contains(T item) => m_target.Contains(item);
public override void CopyTo(T[] array, int arrayIndex) => m_target.CopyTo(array, arrayIndex);
public override IEnumerator<T> GetEnumerator() => m_target.GetEnumerator();
public override int IndexOf(T item) => m_target.IndexOf(item);
protected override T Lookup(int index) => m_target[index];
}
}
|