aboutsummaryrefslogtreecommitdiff
path: root/src/ProtocolBuffers/Collections
diff options
context:
space:
mode:
authorcsharptest <roger@csharptest.net>2011-05-20 15:15:34 -0500
committerrogerk <devnull@localhost>2011-05-20 15:15:34 -0500
commit71f662c33e9938951eec3da97140aed25aa815d7 (patch)
treec322e13686cad5c8bff9e54d7585fc8e4adf6537 /src/ProtocolBuffers/Collections
parentd965c666ecf405f4e997ab251e72551508a14678 (diff)
downloadprotobuf-71f662c33e9938951eec3da97140aed25aa815d7.tar.gz
protobuf-71f662c33e9938951eec3da97140aed25aa815d7.tar.bz2
protobuf-71f662c33e9938951eec3da97140aed25aa815d7.zip
reformatted all code to .NET standard formatting
Diffstat (limited to 'src/ProtocolBuffers/Collections')
-rw-r--r--src/ProtocolBuffers/Collections/Dictionaries.cs230
-rw-r--r--src/ProtocolBuffers/Collections/Enumerables.cs137
-rw-r--r--src/ProtocolBuffers/Collections/IPopsicleList.cs98
-rw-r--r--src/ProtocolBuffers/Collections/Lists.cs209
-rw-r--r--src/ProtocolBuffers/Collections/PopsicleList.cs282
-rw-r--r--src/ProtocolBuffers/Collections/ReadOnlyDictionary.cs274
6 files changed, 652 insertions, 578 deletions
diff --git a/src/ProtocolBuffers/Collections/Dictionaries.cs b/src/ProtocolBuffers/Collections/Dictionaries.cs
index 2a580385..1f3791b1 100644
--- a/src/ProtocolBuffers/Collections/Dictionaries.cs
+++ b/src/ProtocolBuffers/Collections/Dictionaries.cs
@@ -1,108 +1,122 @@
-// Protocol Buffers - Google's data interchange format
-// Copyright 2008 Google Inc. All rights reserved.
-// http://github.com/jskeet/dotnet-protobufs/
-// Original C++/Java/Python code:
-// http://code.google.com/p/protobuf/
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-using System;
-using System.Collections;
-using System.Collections.Generic;
-
-namespace Google.ProtocolBuffers.Collections {
-
- /// <summary>
- /// Utility class for dictionaries.
- /// </summary>
- public static class Dictionaries {
-
- /// <summary>
- /// Compares two dictionaries for equality. Each value is compared with equality using Equals
- /// for non-IEnumerable implementations, and using EnumerableEquals otherwise.
- /// TODO(jonskeet): This is clearly pretty slow, and involves lots of boxing/unboxing...
- /// </summary>
- public static bool Equals<TKey, TValue>(IDictionary<TKey, TValue> left, IDictionary<TKey, TValue> right) {
- if (left.Count != right.Count) {
- return false;
- }
- foreach (KeyValuePair<TKey,TValue> leftEntry in left)
- {
- TValue rightValue;
- if (!right.TryGetValue(leftEntry.Key, out rightValue)) {
- return false;
- }
-
- IEnumerable leftEnumerable = leftEntry.Value as IEnumerable;
- IEnumerable rightEnumerable = rightValue as IEnumerable;
- if (leftEnumerable == null || rightEnumerable == null) {
- if (!Equals(leftEntry.Value, rightValue)) {
- return false;
- }
- } else {
- if (!Enumerables.Equals(leftEnumerable, rightEnumerable)) {
- return false;
- }
- }
- }
- return true;
- }
-
- public static IDictionary<TKey, TValue> AsReadOnly<TKey, TValue> (IDictionary<TKey, TValue> dictionary) {
- return dictionary.IsReadOnly ? dictionary : new ReadOnlyDictionary<TKey, TValue>(dictionary);
- }
-
- /// <summary>
- /// Creates a hashcode for a dictionary by XORing the hashcodes of all the fields
- /// and values. (By XORing, we avoid ordering issues.)
- /// TODO(jonskeet): Currently XORs other stuff too, and assumes non-null values.
- /// </summary>
- public static int GetHashCode<TKey, TValue>(IDictionary<TKey, TValue> dictionary) {
- int ret = 31;
- foreach (KeyValuePair<TKey, TValue> entry in dictionary) {
- int hash = entry.Key.GetHashCode() ^ GetDeepHashCode(entry.Value);
- ret ^= hash;
- }
- return ret;
- }
-
- /// <summary>
- /// Determines the hash of a value by either taking it directly or hashing all the elements
- /// for IEnumerable implementations.
- /// </summary>
- private static int GetDeepHashCode(object value) {
- IEnumerable iterable = value as IEnumerable;
- if (iterable == null) {
- return value.GetHashCode();
- }
- int hash = 29;
- foreach (object element in iterable) {
- hash = hash * 37 + element.GetHashCode();
- }
- return hash;
- }
- }
-}
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://github.com/jskeet/dotnet-protobufs/
+// Original C++/Java/Python code:
+// http://code.google.com/p/protobuf/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+using System;
+using System.Collections;
+using System.Collections.Generic;
+
+namespace Google.ProtocolBuffers.Collections
+{
+ /// <summary>
+ /// Utility class for dictionaries.
+ /// </summary>
+ public static class Dictionaries
+ {
+ /// <summary>
+ /// Compares two dictionaries for equality. Each value is compared with equality using Equals
+ /// for non-IEnumerable implementations, and using EnumerableEquals otherwise.
+ /// TODO(jonskeet): This is clearly pretty slow, and involves lots of boxing/unboxing...
+ /// </summary>
+ public static bool Equals<TKey, TValue>(IDictionary<TKey, TValue> left, IDictionary<TKey, TValue> right)
+ {
+ if (left.Count != right.Count)
+ {
+ return false;
+ }
+ foreach (KeyValuePair<TKey, TValue> leftEntry in left)
+ {
+ TValue rightValue;
+ if (!right.TryGetValue(leftEntry.Key, out rightValue))
+ {
+ return false;
+ }
+
+ IEnumerable leftEnumerable = leftEntry.Value as IEnumerable;
+ IEnumerable rightEnumerable = rightValue as IEnumerable;
+ if (leftEnumerable == null || rightEnumerable == null)
+ {
+ if (!Equals(leftEntry.Value, rightValue))
+ {
+ return false;
+ }
+ }
+ else
+ {
+ if (!Enumerables.Equals(leftEnumerable, rightEnumerable))
+ {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+
+ public static IDictionary<TKey, TValue> AsReadOnly<TKey, TValue>(IDictionary<TKey, TValue> dictionary)
+ {
+ return dictionary.IsReadOnly ? dictionary : new ReadOnlyDictionary<TKey, TValue>(dictionary);
+ }
+
+ /// <summary>
+ /// Creates a hashcode for a dictionary by XORing the hashcodes of all the fields
+ /// and values. (By XORing, we avoid ordering issues.)
+ /// TODO(jonskeet): Currently XORs other stuff too, and assumes non-null values.
+ /// </summary>
+ public static int GetHashCode<TKey, TValue>(IDictionary<TKey, TValue> dictionary)
+ {
+ int ret = 31;
+ foreach (KeyValuePair<TKey, TValue> entry in dictionary)
+ {
+ int hash = entry.Key.GetHashCode() ^ GetDeepHashCode(entry.Value);
+ ret ^= hash;
+ }
+ return ret;
+ }
+
+ /// <summary>
+ /// Determines the hash of a value by either taking it directly or hashing all the elements
+ /// for IEnumerable implementations.
+ /// </summary>
+ private static int GetDeepHashCode(object value)
+ {
+ IEnumerable iterable = value as IEnumerable;
+ if (iterable == null)
+ {
+ return value.GetHashCode();
+ }
+ int hash = 29;
+ foreach (object element in iterable)
+ {
+ hash = hash*37 + element.GetHashCode();
+ }
+ return hash;
+ }
+ }
+} \ No newline at end of file
diff --git a/src/ProtocolBuffers/Collections/Enumerables.cs b/src/ProtocolBuffers/Collections/Enumerables.cs
index 0f77ad9a..7ad9a832 100644
--- a/src/ProtocolBuffers/Collections/Enumerables.cs
+++ b/src/ProtocolBuffers/Collections/Enumerables.cs
@@ -1,63 +1,74 @@
-// Protocol Buffers - Google's data interchange format
-// Copyright 2008 Google Inc. All rights reserved.
-// http://github.com/jskeet/dotnet-protobufs/
-// Original C++/Java/Python code:
-// http://code.google.com/p/protobuf/
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-using System;
-using System.Collections;
-
-namespace Google.ProtocolBuffers.Collections {
- /// <summary>
- /// Utility class for IEnumerable (and potentially the generic version in the future).
- /// </summary>
- public static class Enumerables {
- public static bool Equals(IEnumerable left, IEnumerable right) {
- IEnumerator leftEnumerator = left.GetEnumerator();
- try {
- foreach (object rightObject in right) {
- if (!leftEnumerator.MoveNext()) {
- return false;
- }
- if (!Equals(leftEnumerator.Current, rightObject)) {
- return false;
- }
- }
- if (leftEnumerator.MoveNext()) {
- return false;
- }
- } finally {
- IDisposable leftEnumeratorDisposable = leftEnumerator as IDisposable;
- if (leftEnumeratorDisposable != null) {
- leftEnumeratorDisposable.Dispose();
- }
- }
- return true;
- }
- }
-}
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://github.com/jskeet/dotnet-protobufs/
+// Original C++/Java/Python code:
+// http://code.google.com/p/protobuf/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+using System;
+using System.Collections;
+
+namespace Google.ProtocolBuffers.Collections
+{
+ /// <summary>
+ /// Utility class for IEnumerable (and potentially the generic version in the future).
+ /// </summary>
+ public static class Enumerables
+ {
+ public static bool Equals(IEnumerable left, IEnumerable right)
+ {
+ IEnumerator leftEnumerator = left.GetEnumerator();
+ try
+ {
+ foreach (object rightObject in right)
+ {
+ if (!leftEnumerator.MoveNext())
+ {
+ return false;
+ }
+ if (!Equals(leftEnumerator.Current, rightObject))
+ {
+ return false;
+ }
+ }
+ if (leftEnumerator.MoveNext())
+ {
+ return false;
+ }
+ }
+ finally
+ {
+ IDisposable leftEnumeratorDisposable = leftEnumerator as IDisposable;
+ if (leftEnumeratorDisposable != null)
+ {
+ leftEnumeratorDisposable.Dispose();
+ }
+ }
+ return true;
+ }
+ }
+} \ No newline at end of file
diff --git a/src/ProtocolBuffers/Collections/IPopsicleList.cs b/src/ProtocolBuffers/Collections/IPopsicleList.cs
index de59de94..7f6fd8bc 100644
--- a/src/ProtocolBuffers/Collections/IPopsicleList.cs
+++ b/src/ProtocolBuffers/Collections/IPopsicleList.cs
@@ -1,48 +1,50 @@
-// Protocol Buffers - Google's data interchange format
-// Copyright 2008 Google Inc. All rights reserved.
-// http://github.com/jskeet/dotnet-protobufs/
-// Original C++/Java/Python code:
-// http://code.google.com/p/protobuf/
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-using System.Collections.Generic;
-
-namespace Google.ProtocolBuffers.Collections {
- /// <summary>
- /// A list which has an Add method which accepts an IEnumerable[T].
- /// This allows whole collections to be added easily using collection initializers.
- /// It causes a potential overload confusion if T : IEnumerable[T], but in
- /// practice that won't happen in protocol buffers.
- /// </summary>
- /// <remarks>This is only currently implemented by PopsicleList, and it's likely
- /// to stay that way - hence the name. More genuinely descriptive names are
- /// horribly ugly. (At least, the ones the author could think of...)</remarks>
- /// <typeparam name="T">The element type of the list</typeparam>
- public interface IPopsicleList<T> : IList<T> {
- void Add(IEnumerable<T> collection);
- }
-}
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://github.com/jskeet/dotnet-protobufs/
+// Original C++/Java/Python code:
+// http://code.google.com/p/protobuf/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+using System.Collections.Generic;
+
+namespace Google.ProtocolBuffers.Collections
+{
+ /// <summary>
+ /// A list which has an Add method which accepts an IEnumerable[T].
+ /// This allows whole collections to be added easily using collection initializers.
+ /// It causes a potential overload confusion if T : IEnumerable[T], but in
+ /// practice that won't happen in protocol buffers.
+ /// </summary>
+ /// <remarks>This is only currently implemented by PopsicleList, and it's likely
+ /// to stay that way - hence the name. More genuinely descriptive names are
+ /// horribly ugly. (At least, the ones the author could think of...)</remarks>
+ /// <typeparam name="T">The element type of the list</typeparam>
+ public interface IPopsicleList<T> : IList<T>
+ {
+ void Add(IEnumerable<T> collection);
+ }
+} \ No newline at end of file
diff --git a/src/ProtocolBuffers/Collections/Lists.cs b/src/ProtocolBuffers/Collections/Lists.cs
index 899baae5..a24e1d9b 100644
--- a/src/ProtocolBuffers/Collections/Lists.cs
+++ b/src/ProtocolBuffers/Collections/Lists.cs
@@ -1,99 +1,110 @@
-// Protocol Buffers - Google's data interchange format
-// Copyright 2008 Google Inc. All rights reserved.
-// http://github.com/jskeet/dotnet-protobufs/
-// Original C++/Java/Python code:
-// http://code.google.com/p/protobuf/
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-using System.Collections.Generic;
-using System.Collections.ObjectModel;
-
-namespace Google.ProtocolBuffers.Collections {
-
- /// <summary>
- /// Utility non-generic class for calling into Lists{T} using type inference.
- /// </summary>
- public static class Lists {
-
- /// <summary>
- /// Returns a read-only view of the specified list.
- /// </summary>
- public static IList<T> AsReadOnly<T>(IList<T> list) {
- return Lists<T>.AsReadOnly(list);
- }
-
- public static bool Equals<T>(IList<T> left, IList<T> right) {
- if (left == right) {
- return true;
- }
- if (left == null || right == null) {
- return false;
- }
- if (left.Count != right.Count) {
- return false;
- }
- IEqualityComparer<T> comparer = EqualityComparer<T>.Default;
- for (int i = 0; i < left.Count; i++) {
- if (!comparer.Equals(left[i], right[i])) {
- return false;
- }
- }
- return true;
- }
-
- public static int GetHashCode<T>(IList<T> list) {
- int hash = 31;
- foreach (T element in list) {
- hash = hash * 29 + element.GetHashCode();
- }
- return hash;
- }
- }
-
- /// <summary>
- /// Utility class for dealing with lists.
- /// </summary>
- public static class Lists<T> {
-
- static readonly ReadOnlyCollection<T> empty = new ReadOnlyCollection<T>(new T[0]);
-
- /// <summary>
- /// Returns an immutable empty list.
- /// </summary>
- public static ReadOnlyCollection<T> Empty {
- get { return empty; }
- }
-
- /// <summary>
- /// Returns either the original reference if it's already read-only,
- /// or a new ReadOnlyCollection wrapping the original list.
- /// </summary>
- public static IList<T> AsReadOnly(IList<T> list) {
- return list.IsReadOnly ? list : new ReadOnlyCollection<T>(list);
- }
- }
-}
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://github.com/jskeet/dotnet-protobufs/
+// Original C++/Java/Python code:
+// http://code.google.com/p/protobuf/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+
+namespace Google.ProtocolBuffers.Collections
+{
+ /// <summary>
+ /// Utility non-generic class for calling into Lists{T} using type inference.
+ /// </summary>
+ public static class Lists
+ {
+ /// <summary>
+ /// Returns a read-only view of the specified list.
+ /// </summary>
+ public static IList<T> AsReadOnly<T>(IList<T> list)
+ {
+ return Lists<T>.AsReadOnly(list);
+ }
+
+ public static bool Equals<T>(IList<T> left, IList<T> right)
+ {
+ if (left == right)
+ {
+ return true;
+ }
+ if (left == null || right == null)
+ {
+ return false;
+ }
+ if (left.Count != right.Count)
+ {
+ return false;
+ }
+ IEqualityComparer<T> comparer = EqualityComparer<T>.Default;
+ for (int i = 0; i < left.Count; i++)
+ {
+ if (!comparer.Equals(left[i], right[i]))
+ {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ public static int GetHashCode<T>(IList<T> list)
+ {
+ int hash = 31;
+ foreach (T element in list)
+ {
+ hash = hash*29 + element.GetHashCode();
+ }
+ return hash;
+ }
+ }
+
+ /// <summary>
+ /// Utility class for dealing with lists.
+ /// </summary>
+ public static class Lists<T>
+ {
+ private static readonly ReadOnlyCollection<T> empty = new ReadOnlyCollection<T>(new T[0]);
+
+ /// <summary>
+ /// Returns an immutable empty list.
+ /// </summary>
+ public static ReadOnlyCollection<T> Empty
+ {
+ get { return empty; }
+ }
+
+ /// <summary>
+ /// Returns either the original reference if it's already read-only,
+ /// or a new ReadOnlyCollection wrapping the original list.
+ /// </summary>
+ public static IList<T> AsReadOnly(IList<T> list)
+ {
+ return list.IsReadOnly ? list : new ReadOnlyCollection<T>(list);
+ }
+ }
+} \ No newline at end of file
diff --git a/src/ProtocolBuffers/Collections/PopsicleList.cs b/src/ProtocolBuffers/Collections/PopsicleList.cs
index 26996d9b..33324303 100644
--- a/src/ProtocolBuffers/Collections/PopsicleList.cs
+++ b/src/ProtocolBuffers/Collections/PopsicleList.cs
@@ -1,132 +1,150 @@
-// Protocol Buffers - Google's data interchange format
-// Copyright 2008 Google Inc. All rights reserved.
-// http://github.com/jskeet/dotnet-protobufs/
-// Original C++/Java/Python code:
-// http://code.google.com/p/protobuf/
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-using System;
-using System.Collections.Generic;
-using System.Collections;
-
-namespace Google.ProtocolBuffers.Collections {
- /// <summary>
- /// Proxies calls to a <see cref="List{T}" />, but allows the list
- /// to be made read-only (with the <see cref="MakeReadOnly" /> method),
- /// after which any modifying methods throw <see cref="NotSupportedException" />.
- /// </summary>
- public sealed class PopsicleList<T> : IPopsicleList<T> {
-
- private readonly List<T> items = new List<T>();
- private bool readOnly = false;
-
- /// <summary>
- /// Makes this list read-only ("freezes the popsicle"). From this
- /// point on, mutating methods (Clear, Add etc) will throw a
- /// NotSupportedException. There is no way of "defrosting" the list afterwards.
- /// </summary>
- public void MakeReadOnly() {
- readOnly = true;
- }
-
- public int IndexOf(T item) {
- return items.IndexOf(item);
- }
-
- public void Insert(int index, T item) {
- ValidateModification();
- items.Insert(index, item);
- }
-
- public void RemoveAt(int index) {
- ValidateModification();
- items.RemoveAt(index);
- }
-
- public T this[int index] {
- get {
- return items[index];
- }
- set {
- ValidateModification();
- items[index] = value;
- }
- }
-
- public void Add(T item) {
- ValidateModification();
- items.Add(item);
- }
-
- public void Clear() {
- ValidateModification();
- items.Clear();
- }
-
- public bool Contains(T item) {
- return items.Contains(item);
- }
-
- public void CopyTo(T[] array, int arrayIndex) {
- items.CopyTo(array, arrayIndex);
- }
-
- public int Count {
- get { return items.Count; }
- }
-
- public bool IsReadOnly {
- get { return readOnly; }
- }
-
- public bool Remove(T item) {
- ValidateModification();
- return items.Remove(item);
- }
-
- public void Add(IEnumerable<T> collection) {
- if (readOnly) {
- throw new NotSupportedException("List is read-only");
- }
- items.AddRange(collection);
- }
-
- public IEnumerator<T> GetEnumerator() {
- return items.GetEnumerator();
- }
-
- IEnumerator IEnumerable.GetEnumerator() {
- return GetEnumerator();
- }
-
- private void ValidateModification() {
- if (readOnly) {
- throw new NotSupportedException("List is read-only");
- }
- }
- }
-}
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://github.com/jskeet/dotnet-protobufs/
+// Original C++/Java/Python code:
+// http://code.google.com/p/protobuf/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+using System;
+using System.Collections.Generic;
+using System.Collections;
+
+namespace Google.ProtocolBuffers.Collections
+{
+ /// <summary>
+ /// Proxies calls to a <see cref="List{T}" />, but allows the list
+ /// to be made read-only (with the <see cref="MakeReadOnly" /> method),
+ /// after which any modifying methods throw <see cref="NotSupportedException" />.
+ /// </summary>
+ public sealed class PopsicleList<T> : IPopsicleList<T>
+ {
+ private readonly List<T> items = new List<T>();
+ private bool readOnly = false;
+
+ /// <summary>
+ /// Makes this list read-only ("freezes the popsicle"). From this
+ /// point on, mutating methods (Clear, Add etc) will throw a
+ /// NotSupportedException. There is no way of "defrosting" the list afterwards.
+ /// </summary>
+ public void MakeReadOnly()
+ {
+ readOnly = true;
+ }
+
+ public int IndexOf(T item)
+ {
+ return items.IndexOf(item);
+ }
+
+ public void Insert(int index, T item)
+ {
+ ValidateModification();
+ items.Insert(index, item);
+ }
+
+ public void RemoveAt(int index)
+ {
+ ValidateModification();
+ items.RemoveAt(index);
+ }
+
+ public T this[int index]
+ {
+ get { return items[index]; }
+ set
+ {
+ ValidateModification();
+ items[index] = value;
+ }
+ }
+
+ public void Add(T item)
+ {
+ ValidateModification();
+ items.Add(item);
+ }
+
+ public void Clear()
+ {
+ ValidateModification();
+ items.Clear();
+ }
+
+ public bool Contains(T item)
+ {
+ return items.Contains(item);
+ }
+
+ public void CopyTo(T[] array, int arrayIndex)
+ {
+ items.CopyTo(array, arrayIndex);
+ }
+
+ public int Count
+ {
+ get { return items.Count; }
+ }
+
+ public bool IsReadOnly
+ {
+ get { return readOnly; }
+ }
+
+ public bool Remove(T item)
+ {
+ ValidateModification();
+ return items.Remove(item);
+ }
+
+ public void Add(IEnumerable<T> collection)
+ {
+ if (readOnly)
+ {
+ throw new NotSupportedException("List is read-only");
+ }
+ items.AddRange(collection);
+ }
+
+ public IEnumerator<T> GetEnumerator()
+ {
+ return items.GetEnumerator();
+ }
+
+ IEnumerator IEnumerable.GetEnumerator()
+ {
+ return GetEnumerator();
+ }
+
+ private void ValidateModification()
+ {
+ if (readOnly)
+ {
+ throw new NotSupportedException("List is read-only");
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/src/ProtocolBuffers/Collections/ReadOnlyDictionary.cs b/src/ProtocolBuffers/Collections/ReadOnlyDictionary.cs
index 3be460dc..b0bc55ff 100644
--- a/src/ProtocolBuffers/Collections/ReadOnlyDictionary.cs
+++ b/src/ProtocolBuffers/Collections/ReadOnlyDictionary.cs
@@ -1,128 +1,146 @@
-// Protocol Buffers - Google's data interchange format
-// Copyright 2008 Google Inc. All rights reserved.
-// http://github.com/jskeet/dotnet-protobufs/
-// Original C++/Java/Python code:
-// http://code.google.com/p/protobuf/
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-using System;
-using System.Collections;
-using System.Collections.Generic;
-
-namespace Google.ProtocolBuffers.Collections {
- /// <summary>
- /// Read-only wrapper around another dictionary.
- /// </summary>
- public sealed class ReadOnlyDictionary<TKey, TValue> : IDictionary<TKey, TValue> {
- readonly IDictionary<TKey, TValue> wrapped;
-
- public ReadOnlyDictionary(IDictionary<TKey, TValue> wrapped) {
- this.wrapped = wrapped;
- }
-
- public void Add(TKey key, TValue value) {
- throw new InvalidOperationException();
- }
-
- public bool ContainsKey(TKey key) {
- return wrapped.ContainsKey(key);
- }
-
- public ICollection<TKey> Keys {
- get { return wrapped.Keys; }
- }
-
- public bool Remove(TKey key) {
- throw new InvalidOperationException();
- }
-
- public bool TryGetValue(TKey key, out TValue value) {
- return wrapped.TryGetValue(key, out value);
- }
-
- public ICollection<TValue> Values {
- get { return wrapped.Values; }
- }
-
- public TValue this[TKey key] {
- get {
- return wrapped[key];
- }
- set {
- throw new InvalidOperationException();
- }
- }
-
- public void Add(KeyValuePair<TKey, TValue> item) {
- throw new InvalidOperationException();
- }
-
- public void Clear() {
- throw new InvalidOperationException();
- }
-
- public bool Contains(KeyValuePair<TKey, TValue> item) {
- return wrapped.Contains(item);
- }
-
- public void CopyTo(KeyValuePair<TKey, TValue>[] array, int arrayIndex) {
- wrapped.CopyTo(array, arrayIndex);
- }
-
- public int Count {
- get { return wrapped.Count; }
- }
-
- public bool IsReadOnly {
- get { return true; }
- }
-
- public bool Remove(KeyValuePair<TKey, TValue> item) {
- throw new InvalidOperationException();
- }
-
- public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator() {
- return wrapped.GetEnumerator();
- }
-
- IEnumerator IEnumerable.GetEnumerator() {
- return ((IEnumerable) wrapped).GetEnumerator();
- }
-
- public override bool Equals(object obj) {
- return wrapped.Equals(obj);
- }
-
- public override int GetHashCode() {
- return wrapped.GetHashCode();
- }
-
- public override string ToString() {
- return wrapped.ToString();
- }
- }
-}
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc. All rights reserved.
+// http://github.com/jskeet/dotnet-protobufs/
+// Original C++/Java/Python code:
+// http://code.google.com/p/protobuf/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+using System;
+using System.Collections;
+using System.Collections.Generic;
+
+namespace Google.ProtocolBuffers.Collections
+{
+ /// <summary>
+ /// Read-only wrapper around another dictionary.
+ /// </summary>
+ public sealed class ReadOnlyDictionary<TKey, TValue> : IDictionary<TKey, TValue>
+ {
+ private readonly IDictionary<TKey, TValue> wrapped;
+
+ public ReadOnlyDictionary(IDictionary<TKey, TValue> wrapped)
+ {
+ this.wrapped = wrapped;
+ }
+
+ public void Add(TKey key, TValue value)
+ {
+ throw new InvalidOperationException();
+ }
+
+ public bool ContainsKey(TKey key)
+ {
+ return wrapped.ContainsKey(key);
+ }
+
+ public ICollection<TKey> Keys
+ {
+ get { return wrapped.Keys; }
+ }
+
+ public bool Remove(TKey key)
+ {
+ throw new InvalidOperationException();
+ }
+
+ public bool TryGetValue(TKey key, out TValue value)
+ {
+ return wrapped.TryGetValue(key, out value);
+ }
+
+ public ICollection<TValue> Values
+ {
+ get { return wrapped.Values; }
+ }
+
+ public TValue this[TKey key]
+ {
+ get { return wrapped[key]; }
+ set { throw new InvalidOperationException(); }
+ }
+
+ public void Add(KeyValuePair<TKey, TValue> item)
+ {
+ throw new InvalidOperationException();
+ }
+
+ public void Clear()
+ {
+ throw new InvalidOperationException();
+ }
+
+ public bool Contains(KeyValuePair<TKey, TValue> item)
+ {
+ return wrapped.Contains(item);
+ }
+
+ public void CopyTo(KeyValuePair<TKey, TValue>[] array, int arrayIndex)
+ {
+ wrapped.CopyTo(array, arrayIndex);
+ }
+
+ public int Count
+ {
+ get { return wrapped.Count; }
+ }
+
+ public bool IsReadOnly
+ {
+ get { return true; }
+ }
+
+ public bool Remove(KeyValuePair<TKey, TValue> item)
+ {
+ throw new InvalidOperationException();
+ }
+
+ public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()
+ {
+ return wrapped.GetEnumerator();
+ }
+
+ IEnumerator IEnumerable.GetEnumerator()
+ {
+ return ((IEnumerable) wrapped).GetEnumerator();
+ }
+
+ public override bool Equals(object obj)
+ {
+ return wrapped.Equals(obj);
+ }
+
+ public override int GetHashCode()
+ {
+ return wrapped.GetHashCode();
+ }
+
+ public override string ToString()
+ {
+ return wrapped.ToString();
+ }
+ }
+} \ No newline at end of file