Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/cecil.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjbevain <jbevain@gmail.com>2010-09-22 02:15:13 +0400
committerjbevain <jbevain@gmail.com>2010-09-22 02:15:13 +0400
commit37e21b97e375b9349611e63d474bce4c04e7092e (patch)
treeb3137bea75da13d4279b10cc438d3fabfb708f79 /Mono.Collections.Generic
parent9d2443732c80ea8ec93c7d6de29583e125a4a36f (diff)
Expose ReadOnlyCollection
Diffstat (limited to 'Mono.Collections.Generic')
-rw-r--r--Mono.Collections.Generic/Collection.cs2
-rw-r--r--Mono.Collections.Generic/ReadOnlyCollection.cs99
2 files changed, 100 insertions, 1 deletions
diff --git a/Mono.Collections.Generic/Collection.cs b/Mono.Collections.Generic/Collection.cs
index d7628f0..9177e39 100644
--- a/Mono.Collections.Generic/Collection.cs
+++ b/Mono.Collections.Generic/Collection.cs
@@ -237,7 +237,7 @@ namespace Mono.Collections.Generic {
{
}
- void Grow (int desired)
+ internal virtual void Grow (int desired)
{
int new_size = size + desired;
if (new_size <= items.Length)
diff --git a/Mono.Collections.Generic/ReadOnlyCollection.cs b/Mono.Collections.Generic/ReadOnlyCollection.cs
new file mode 100644
index 0000000..61f6912
--- /dev/null
+++ b/Mono.Collections.Generic/ReadOnlyCollection.cs
@@ -0,0 +1,99 @@
+//
+// ReadOnlyCollection.cs
+//
+// Author:
+// Jb Evain (jbevain@gmail.com)
+//
+// Copyright (c) 2008 - 2010 Jb Evain
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using System.Collections;
+
+namespace Mono.Collections.Generic {
+
+ public sealed class ReadOnlyCollection<T> : Collection<T>, IList {
+
+ static ReadOnlyCollection<T> empty;
+
+ public static ReadOnlyCollection<T> Empty {
+ get { return empty ?? (empty = new ReadOnlyCollection<T> ()); }
+ }
+
+ readonly bool initialized;
+
+ bool IList.IsReadOnly {
+ get { return true; }
+ }
+
+ public ReadOnlyCollection ()
+ {
+ initialized = true;
+ }
+
+ public ReadOnlyCollection (T [] array)
+ : this ()
+ {
+ this.items = array;
+ this.size = array.Length;
+ }
+
+ public ReadOnlyCollection (Collection<T> collection)
+ : this ()
+ {
+ this.items = collection.items;
+ this.size = collection.size;
+ }
+
+ internal override void Grow (int desired)
+ {
+ if (initialized)
+ throw new InvalidOperationException ();
+ }
+
+ protected override void OnAdd (T item, int index)
+ {
+ if (initialized)
+ throw new InvalidOperationException ();
+ }
+
+ protected override void OnClear ()
+ {
+ throw new InvalidOperationException ();
+ }
+
+ protected override void OnInsert (T item, int index)
+ {
+ throw new InvalidOperationException ();
+ }
+
+ protected override void OnRemove (T item, int index)
+ {
+ throw new InvalidOperationException ();
+ }
+
+ protected override void OnSet (T item, int index)
+ {
+ throw new InvalidOperationException ();
+ }
+ }
+}