| 1 |
/****************************************************************************** |
|---|
| 2 |
x42view.net - .x42 viewer and auditing tool |
|---|
| 3 |
Copyright (C) 2007 HermitWorks Entertainment Corporation |
|---|
| 4 |
|
|---|
| 5 |
This program is free software; you can redistribute it and/or modify it |
|---|
| 6 |
under the terms of the GNU General Public License as published by the Free |
|---|
| 7 |
Software Foundation; either version 2 of the License, or (at your option) |
|---|
| 8 |
any later version. |
|---|
| 9 |
|
|---|
| 10 |
This program is distributed in the hope that it will be useful, but |
|---|
| 11 |
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
|---|
| 12 |
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|---|
| 13 |
for more details. |
|---|
| 14 |
|
|---|
| 15 |
You should have received a copy of the GNU General Public License along |
|---|
| 16 |
with this program; if not, write to the |
|---|
| 17 |
|
|---|
| 18 |
Free Software Foundation, Inc. |
|---|
| 19 |
51 Franklin Street, Fifth Floor |
|---|
| 20 |
Boston, MA 02110-1301, USA. |
|---|
| 21 |
******************************************************************************/ |
|---|
| 22 |
|
|---|
| 23 |
using System; |
|---|
| 24 |
using System.Collections.Generic; |
|---|
| 25 |
using System.Text; |
|---|
| 26 |
|
|---|
| 27 |
namespace x42view |
|---|
| 28 |
{ |
|---|
| 29 |
public class ReadOnlyList<T> : IList<T> |
|---|
| 30 |
{ |
|---|
| 31 |
private T[] items; |
|---|
| 32 |
public ReadOnlyList( ICollection<T> items ) |
|---|
| 33 |
{ |
|---|
| 34 |
if( items == null ) |
|---|
| 35 |
throw new ArgumentNullException( "items" ); |
|---|
| 36 |
|
|---|
| 37 |
this.items = new T[items.Count]; |
|---|
| 38 |
items.CopyTo( this.items, 0 ); |
|---|
| 39 |
} |
|---|
| 40 |
|
|---|
| 41 |
public int Count { get { return items.Length; } } |
|---|
| 42 |
public T this[int index] { get { return items[index]; } } |
|---|
| 43 |
|
|---|
| 44 |
private static ReadOnlyList<T> empty; |
|---|
| 45 |
public static ReadOnlyList<T> Empty |
|---|
| 46 |
{ |
|---|
| 47 |
get |
|---|
| 48 |
{ |
|---|
| 49 |
if( empty == null ) |
|---|
| 50 |
empty = new ReadOnlyList<T>( new T[0] ); |
|---|
| 51 |
|
|---|
| 52 |
return empty; |
|---|
| 53 |
} |
|---|
| 54 |
} |
|---|
| 55 |
|
|---|
| 56 |
public int IndexOf( T item ) |
|---|
| 57 |
{ |
|---|
| 58 |
return Array.IndexOf( items, item ); |
|---|
| 59 |
} |
|---|
| 60 |
|
|---|
| 61 |
#region IList<T> Members |
|---|
| 62 |
|
|---|
| 63 |
void IList<T>.Insert( int index, T item ) |
|---|
| 64 |
{ |
|---|
| 65 |
throw new NotSupportedException(); |
|---|
| 66 |
} |
|---|
| 67 |
|
|---|
| 68 |
void IList<T>.RemoveAt( int index ) |
|---|
| 69 |
{ |
|---|
| 70 |
throw new NotSupportedException(); |
|---|
| 71 |
} |
|---|
| 72 |
|
|---|
| 73 |
T IList<T>.this[int index] |
|---|
| 74 |
{ |
|---|
| 75 |
get |
|---|
| 76 |
{ |
|---|
| 77 |
return items[index]; |
|---|
| 78 |
} |
|---|
| 79 |
set |
|---|
| 80 |
{ |
|---|
| 81 |
throw new NotSupportedException(); |
|---|
| 82 |
} |
|---|
| 83 |
} |
|---|
| 84 |
|
|---|
| 85 |
#endregion |
|---|
| 86 |
|
|---|
| 87 |
#region ICollection<T> Members |
|---|
| 88 |
|
|---|
| 89 |
void ICollection<T>.Add( T item ) |
|---|
| 90 |
{ |
|---|
| 91 |
throw new NotSupportedException(); |
|---|
| 92 |
} |
|---|
| 93 |
|
|---|
| 94 |
void ICollection<T>.Clear() |
|---|
| 95 |
{ |
|---|
| 96 |
throw new NotSupportedException(); |
|---|
| 97 |
} |
|---|
| 98 |
|
|---|
| 99 |
public bool Contains( T item ) |
|---|
| 100 |
{ |
|---|
| 101 |
return IndexOf( item ) != -1; |
|---|
| 102 |
} |
|---|
| 103 |
|
|---|
| 104 |
public void CopyTo( T[] array, int arrayIndex ) |
|---|
| 105 |
{ |
|---|
| 106 |
items.CopyTo( array, arrayIndex ); |
|---|
| 107 |
} |
|---|
| 108 |
|
|---|
| 109 |
bool ICollection<T>.IsReadOnly |
|---|
| 110 |
{ |
|---|
| 111 |
get { return true; } |
|---|
| 112 |
} |
|---|
| 113 |
|
|---|
| 114 |
bool ICollection<T>.Remove( T item ) |
|---|
| 115 |
{ |
|---|
| 116 |
throw new NotSupportedException(); |
|---|
| 117 |
} |
|---|
| 118 |
|
|---|
| 119 |
#endregion |
|---|
| 120 |
|
|---|
| 121 |
#region IEnumerable<T> Members |
|---|
| 122 |
|
|---|
| 123 |
public IEnumerator<T> GetEnumerator() |
|---|
| 124 |
{ |
|---|
| 125 |
return ((IEnumerable<T>)items).GetEnumerator(); |
|---|
| 126 |
} |
|---|
| 127 |
|
|---|
| 128 |
#endregion |
|---|
| 129 |
|
|---|
| 130 |
#region IEnumerable Members |
|---|
| 131 |
|
|---|
| 132 |
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() |
|---|
| 133 |
{ |
|---|
| 134 |
return GetEnumerator(); |
|---|
| 135 |
} |
|---|
| 136 |
|
|---|
| 137 |
#endregion |
|---|
| 138 |
} |
|---|
| 139 |
} |
|---|