Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

View File

@ -0,0 +1,60 @@
2010-06-09 Jonathan Pryor <jpryor@novell.com>
* KeyedCollection.cs: Make KeyedCollection.InsertItem() exception
safe, so that if the index is invalid (negative or too large) we
don't add the entry to the underlying Dictionary.
2008-06-27 Andreas Nahr <ClassDevelopment@A-SoftTech.com>
* Collection.cs: Fix parameter names
* ReadOnlyCollection.cs: Fix parameter names
2008-04-02 Andreas Nahr <ClassDevelopment@A-SoftTech.com>
* ReadOnlyCollection.cs: Fix parameter names
2008-01-20 Juraj Skripsky <js@hotfeet.ch>
* ReadOnlyCollection.cs: Fix the getters for ICollection.IsSynchronized,
ICollection.SyncRoot and IList.IsFixedSize to match MS.NET.
2008-01-13 Juraj Skripsky <js@hotfeet.ch>
* Collection.cs, ReadonlyCollection.cs (ICollection.CopyTo):
Use ICollection.CopyTo of inner list. Fixes bug #350432.
2006-08-08 Atsushi Enomoto <atsushi@ximian.com>
* ReadOnlyCollection.cs : added get_IList<T>.this(int).
2006-03-28 Atsushi Enomoto <atsushi@ximian.com>
* Collection.cs : Count and Item are not virtual.
2006-01-24 Raja R Harinath <rharinath@novell.com>
* ReadOnlyCollection.cs (Items): Return underlying list.
2005-12-19 Sebastien Pouliot <sebastien@ximian.com>
* Collection.cs: IsReadOnly property isn't public in 2.0 final.
* ReadOnlyCollection.cs: Fixed API to match 2.0 final.
2005-10-27 Atsushi Enomoto <atsushi@ximian.com>
* Collection.cs : added Items.
2005-10-25 Carlo Kok <ck@carlo-kok.com>
* Collection.cs :
Added virtual ClearItems, InsertItem, RemoveItem, SetITem.
* KeyedCollection.cs : Implemented.
2005-06-19 David Waite <mass@akuma.org>
* Collection.cs ReadonlyCollection.cs: Implement all methods
2005-06-19 Zoltan Varga <vargaz@freemail.hu>
* Collection.cs KeyedCollection.cs ReadOnlyCollection.cs: New files.

View File

@ -0,0 +1,271 @@
// -*- Mode: csharp; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
//
// System.Collections.ObjectModel.Collection
//
// Authors:
// Zoltan Varga (vargaz@gmail.com)
// David Waite (mass@akuma.org)
// Marek Safar (marek.safar@gmail.com)
//
// (C) 2005 Novell, Inc.
// (C) 2005 David Waite
//
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
// Copyright (C) 2005 David Waite
// Copyright (C) 2011 Xamarin, Inc (http://www.xamarin.com)
//
// 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;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Diagnostics;
namespace System.Collections.ObjectModel
{
[ComVisible (false)]
[Serializable]
[DebuggerDisplay ("Count={Count}")]
[DebuggerTypeProxy (typeof (CollectionDebuggerView<>))]
public class Collection<T> : IList<T>, IList
#if NET_4_5
, IReadOnlyList<T>
#endif
{
IList <T> items;
[NonSerialized]
object syncRoot;
public Collection ()
{
List <T> l = new List <T> ();
IList l2 = l as IList;
syncRoot = l2.SyncRoot;
items = l;
}
public Collection (IList <T> list)
{
if (list == null)
throw new ArgumentNullException ("list");
this.items = list;
ICollection l = list as ICollection;
syncRoot = (l != null) ? l.SyncRoot : new object ();
}
public void Add (T item)
{
int idx = items.Count;
InsertItem (idx, item);
}
public void Clear ()
{
ClearItems ();
}
protected virtual void ClearItems ()
{
items.Clear ();
}
public bool Contains (T item)
{
return items.Contains (item);
}
public void CopyTo (T [] array, int index)
{
items.CopyTo (array, index);
}
public IEnumerator <T> GetEnumerator ()
{
return items.GetEnumerator ();
}
public int IndexOf (T item)
{
return items.IndexOf (item);
}
public void Insert (int index, T item)
{
InsertItem (index, item);
}
protected virtual void InsertItem (int index, T item)
{
items.Insert (index, item);
}
protected IList<T> Items {
get { return items; }
}
public bool Remove (T item)
{
int idx = IndexOf (item);
if (idx == -1)
return false;
RemoveItem (idx);
return true;
}
public void RemoveAt (int index)
{
RemoveItem (index);
}
protected virtual void RemoveItem (int index)
{
items.RemoveAt (index);
}
public int Count {
get { return items.Count; }
}
public T this [int index] {
get { return items [index]; }
set { SetItem (index, value); }
}
bool ICollection<T>.IsReadOnly {
get { return items.IsReadOnly; }
}
protected virtual void SetItem (int index, T item)
{
items[index] = item;
}
#region Helper methods for non-generic interfaces
internal static T ConvertItem (object item)
{
if (CollectionHelpers.IsValidItem<T> (item))
return (T)item;
throw new ArgumentException ("item");
}
internal static void CheckWritable (IList <T> items)
{
if (items.IsReadOnly)
throw new NotSupportedException ();
}
internal static bool IsSynchronized (IList <T> items)
{
ICollection c = items as ICollection;
return (c != null) ? c.IsSynchronized : false;
}
internal static bool IsFixedSize (IList <T> items)
{
IList l = items as IList;
return (l != null) ? l.IsFixedSize : false;
}
#endregion
#region Not generic interface implementations
void ICollection.CopyTo (Array array, int index)
{
((ICollection)items).CopyTo (array, index);
}
IEnumerator IEnumerable.GetEnumerator ()
{
return (IEnumerator) items.GetEnumerator ();
}
int IList.Add (object value)
{
int idx = items.Count;
InsertItem (idx, ConvertItem (value));
return idx;
}
bool IList.Contains (object value)
{
if (CollectionHelpers.IsValidItem<T> (value))
return items.Contains ((T) value);
return false;
}
int IList.IndexOf (object value)
{
if (CollectionHelpers.IsValidItem<T> (value))
return items.IndexOf ((T) value);
return -1;
}
void IList.Insert (int index, object value)
{
InsertItem (index, ConvertItem (value));
}
void IList.Remove (object value)
{
CheckWritable (items);
int idx = IndexOf (ConvertItem (value));
RemoveItem (idx);
}
bool ICollection.IsSynchronized {
get { return IsSynchronized (items); }
}
object ICollection.SyncRoot {
get { return syncRoot; }
}
bool IList.IsFixedSize {
get { return IsFixedSize (items); }
}
bool IList.IsReadOnly {
get { return items.IsReadOnly; }
}
object IList.this [int index] {
get { return items [index]; }
set { SetItem (index, ConvertItem (value)); }
}
#endregion
}
static class CollectionHelpers
{
public static bool IsValidItem<T> (object item)
{
return item is T || (item == null && ! typeof (T).IsValueType);
}
}
}

View File

@ -0,0 +1,217 @@
// -*- Mode: csharp; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
//
// System.Collections.ObjectModel.KeyedCollection
//
// Author:
// Zoltan Varga (vargaz@gmail.com)
//
// (C) 2005 Novell, Inc.
//
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// 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.Generic;
using System.Runtime.InteropServices;
using System.Diagnostics;
namespace System.Collections.ObjectModel
{
[ComVisible(false)]
[Serializable]
[DebuggerDisplay ("Count={Count}")]
[DebuggerTypeProxy (typeof (CollectionDebuggerView<,>))]
public abstract class KeyedCollection<TKey, TItem> : Collection<TItem>
{
private Dictionary<TKey, TItem> dictionary;
private IEqualityComparer<TKey> comparer;
private int dictionaryCreationThreshold;
protected KeyedCollection ()
: this (null, 0)
{
}
protected KeyedCollection (IEqualityComparer<TKey> comparer)
: this(comparer, 0)
{
}
protected KeyedCollection (IEqualityComparer<TKey> comparer, int dictionaryCreationThreshold)
{
if (comparer != null)
this.comparer = comparer;
else
this.comparer = EqualityComparer<TKey>.Default;
this.dictionaryCreationThreshold = dictionaryCreationThreshold;
if (dictionaryCreationThreshold == 0)
dictionary = new Dictionary<TKey, TItem> (this.comparer);
}
public bool Contains (TKey key)
{
if (dictionary != null)
return dictionary.ContainsKey (key);
return IndexOfKey (key) >= 0;
}
private int IndexOfKey (TKey key)
{
for (int i = Count - 1; i >= 0; i--)
{
TKey lkey = GetKeyForItem (this [i]);
if (comparer.Equals (key, lkey))
return i;
}
return -1;
}
public bool Remove (TKey key)
{
TItem item;
if (dictionary != null)
{
if (dictionary.TryGetValue (key, out item))
return base.Remove(item);
else
return false;
}
int idx = IndexOfKey (key);
if (idx == -1)
return false;
RemoveAt(idx);
return true;
}
public IEqualityComparer<TKey> Comparer {
get {
return comparer;
}
}
public TItem this [TKey key] {
get {
if (dictionary != null)
return dictionary [key];
int idx = IndexOfKey (key);
if (idx >= 0)
return base [idx];
else
throw new KeyNotFoundException();
}
}
protected void ChangeItemKey (TItem item, TKey newKey)
{
if (!Contains(item)) throw new ArgumentException();
TKey oldKey = GetKeyForItem (item);
if (comparer.Equals (oldKey, newKey)) return;
if (Contains (newKey)) throw new ArgumentException();
if (dictionary != null)
{
if (!dictionary.Remove (oldKey))
throw new ArgumentException();
dictionary.Add (newKey, item);
}
}
protected override void ClearItems ()
{
if (dictionary != null)
{
dictionary.Clear();
}
base.ClearItems ();
}
protected abstract TKey GetKeyForItem (TItem item);
protected override void InsertItem (int index, TItem item)
{
TKey key = GetKeyForItem (item);
if (key == null)
throw new ArgumentNullException ("GetKeyForItem(item)");
if (dictionary != null && dictionary.ContainsKey (key))
throw new ArgumentException ("An element with the same key already exists in the dictionary.");
if (dictionary == null)
for (int i = 0; i < Count; ++i) {
if (comparer.Equals (key, GetKeyForItem (this [i]))) {
throw new ArgumentException ("An element with the same key already exists in the dictionary.");
}
}
base.InsertItem (index, item);
if (dictionary != null)
dictionary.Add (key, item);
else if (dictionaryCreationThreshold != -1 && Count > dictionaryCreationThreshold) {
dictionary = new Dictionary<TKey, TItem> (comparer);
for (int i = 0; i < Count; ++i) {
TItem dictitem = this [i];
dictionary.Add (GetKeyForItem (dictitem), dictitem);
}
}
}
protected override void RemoveItem (int index)
{
if (dictionary != null)
{
TKey key = GetKeyForItem (this [index]);
dictionary.Remove (key);
}
base.RemoveItem (index);
}
protected override void SetItem (int index, TItem item)
{
if (dictionary != null)
{
dictionary.Remove (GetKeyForItem (this [index]));
dictionary.Add (GetKeyForItem (item), item);
}
base.SetItem (index, item);
}
protected IDictionary<TKey, TItem> Dictionary {
get {
return dictionary;
}
}
}
}

View File

@ -0,0 +1,202 @@
// -*- Mode: csharp; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
//
// System.Collections.ObjectModel.ReadOnlyCollection
//
// Authors:
// Zoltan Varga (vargaz@gmail.com)
// David Waite (mass@akuma.org)
// Marek Safar (marek.safar@gmail.com)
//
// (C) 2005 Novell, Inc.
// (C) 2005 David Waite
//
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
// Copyright (C) 2005 David Waite
// Copyright (C) 2011 Xamarin, Inc (http://www.xamarin.com)
//
// 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.Generic;
using System.Runtime.InteropServices;
using System.Diagnostics;
namespace System.Collections.ObjectModel
{
[ComVisible (false)]
[Serializable]
[DebuggerDisplay ("Count={Count}")]
[DebuggerTypeProxy (typeof (CollectionDebuggerView<>))]
public class ReadOnlyCollection<T> : IList<T>, IList
#if NET_4_5
, IReadOnlyList<T>
#endif
{
IList <T> list;
public ReadOnlyCollection (IList <T> list)
{
if (list == null)
throw new ArgumentNullException ("list");
this.list = list;
}
void ICollection<T>.Add (T item)
{
throw new NotSupportedException ();
}
void ICollection<T>.Clear ()
{
throw new NotSupportedException ();
}
public bool Contains (T value)
{
return list.Contains (value);
}
public void CopyTo (T [] array, int index)
{
list.CopyTo (array, index);
}
public IEnumerator <T> GetEnumerator ()
{
return list.GetEnumerator ();
}
public int IndexOf (T value)
{
return list.IndexOf (value);
}
void IList<T>.Insert (int index, T item)
{
throw new NotSupportedException ();
}
bool ICollection<T>.Remove (T item)
{
throw new NotSupportedException ();
}
void IList<T>.RemoveAt (int index)
{
throw new NotSupportedException ();
}
public int Count {
get { return list.Count; }
}
protected IList<T> Items {
get { return list; }
}
public T this [int index] {
get { return list [index]; }
}
T IList<T>.this [int index] {
get { return this [index]; }
set { throw new NotSupportedException (); }
}
bool ICollection<T>.IsReadOnly {
get { return true; }
}
#region Not generic interface implementations
void ICollection.CopyTo (Array array, int index)
{
((ICollection)list).CopyTo (array, index);
}
IEnumerator IEnumerable.GetEnumerator ()
{
return ((IEnumerable) list).GetEnumerator ();
}
int IList.Add (object value)
{
throw new NotSupportedException ();
}
void IList.Clear ()
{
throw new NotSupportedException ();
}
bool IList.Contains (object value)
{
if (CollectionHelpers.IsValidItem<T> (value))
return list.Contains ((T) value);
return false;
}
int IList.IndexOf (object value)
{
if (CollectionHelpers.IsValidItem<T> (value))
return list.IndexOf ((T) value);
return -1;
}
void IList.Insert (int index, object value)
{
throw new NotSupportedException ();
}
void IList.Remove (object value)
{
throw new NotSupportedException ();
}
void IList.RemoveAt (int index)
{
throw new NotSupportedException ();
}
bool ICollection.IsSynchronized {
get { return false; }
}
object ICollection.SyncRoot {
get { return this; }
}
bool IList.IsFixedSize {
get { return true; }
}
bool IList.IsReadOnly {
get { return true; }
}
object IList.this [int index] {
get { return list [index]; }
set { throw new NotSupportedException (); }
}
#endregion
}
}

View File

@ -0,0 +1,441 @@
//
// ReadOnlyDictionary.cs
//
// Authors:
// Martin Baulig <martin.baulig@xamarin.com>
// Marek Safar (marek.safar@gmail.com)
//
// Copyright (c) 2013 Xamarin Inc. (http://www.xamarin.com)
//
// 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.
#if NET_4_5
using System;
using System.Collections.Generic;
using System.Diagnostics;
namespace System.Collections.ObjectModel {
[Serializable]
[DebuggerDisplay ("Count={Count}")]
[DebuggerTypeProxy (typeof (CollectionDebuggerView<,>))]
public class ReadOnlyDictionary<TKey, TValue> : IDictionary<TKey, TValue>, IDictionary,
IReadOnlyDictionary<TKey, TValue>
{
readonly IDictionary<TKey, TValue> inner;
public ReadOnlyDictionary (IDictionary<TKey, TValue> dictionary)
{
if (dictionary == null)
throw new ArgumentNullException ("dictionary");
this.inner = dictionary;
}
protected IDictionary<TKey, TValue> Dictionary {
get {
return inner;
}
}
public bool ContainsKey (TKey key)
{
return inner.ContainsKey (key);
}
public bool TryGetValue (TKey key, out TValue value)
{
return inner.TryGetValue (key, out value);
}
public TValue this [TKey key] {
get {
return inner [key];
}
}
public KeyCollection Keys {
get {
return new KeyCollection (inner.Keys);
}
}
public ValueCollection Values {
get {
return new ValueCollection (inner.Values);
}
}
#region IEnumerable<KeyValuePair<TKey, TValue>> implementation
public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator ()
{
return inner.GetEnumerator ();
}
#endregion
#region IEnumerable implementation
IEnumerator IEnumerable.GetEnumerator ()
{
return inner.GetEnumerator ();
}
#endregion
#region IDictionary<TKey, TValue> implementation
void IDictionary<TKey, TValue>.Add (TKey key, TValue value)
{
throw new NotSupportedException ();
}
bool IDictionary<TKey, TValue>.Remove (TKey key)
{
throw new NotSupportedException ();
}
TValue IDictionary<TKey, TValue>.this [TKey key] {
get {
return inner [key];
}
set {
throw new NotSupportedException ();
}
}
ICollection<TKey> IDictionary<TKey, TValue>.Keys {
get {
return Keys;
}
}
ICollection<TValue> IDictionary<TKey, TValue>.Values {
get {
return Values;
}
}
#endregion
#region IDictionary implementation
void IDictionary.Add (object key, object value)
{
throw new NotSupportedException ();
}
void IDictionary.Clear ()
{
throw new NotSupportedException ();
}
bool IDictionary.Contains (object key)
{
return ((IDictionary)inner).Contains (key);
}
IDictionaryEnumerator IDictionary.GetEnumerator ()
{
return ((IDictionary)inner).GetEnumerator ();
}
void IDictionary.Remove (object key)
{
throw new NotSupportedException ();
}
bool IDictionary.IsFixedSize {
get {
return true;
}
}
bool IDictionary.IsReadOnly {
get {
return true;
}
}
object IDictionary.this [object key] {
get {
return ((IDictionary)inner)[key];
}
set {
throw new NotSupportedException ();
}
}
ICollection IDictionary.Keys {
get {
return Keys;
}
}
ICollection IDictionary.Values {
get {
return Values;
}
}
#endregion
#region ICollection implementation
void ICollection.CopyTo (Array array, int index)
{
((ICollection)inner).CopyTo (array, index);
}
#endregion
#region ICollection<KeyValuePair<TKey, TValue>> implementation
void ICollection<KeyValuePair<TKey, TValue>>.Add (KeyValuePair<TKey, TValue> item)
{
throw new NotSupportedException ();
}
void ICollection<KeyValuePair<TKey, TValue>>.Clear ()
{
throw new NotSupportedException ();
}
bool ICollection<KeyValuePair<TKey, TValue>>.Contains (KeyValuePair<TKey, TValue> item)
{
return ((ICollection<KeyValuePair<TKey, TValue>>)inner).Contains (item);
}
void ICollection<KeyValuePair<TKey, TValue>>.CopyTo (KeyValuePair<TKey, TValue>[] array, int arrayIndex)
{
((ICollection<KeyValuePair<TKey, TValue>>)inner).CopyTo (array, arrayIndex);
}
bool ICollection<KeyValuePair<TKey, TValue>>.Remove (KeyValuePair<TKey, TValue> item)
{
throw new NotSupportedException ();
}
bool ICollection<KeyValuePair<TKey, TValue>>.IsReadOnly {
get {
return true;
}
}
#endregion
#region ICollection implementation
public int Count {
get {
return inner.Count;
}
}
bool ICollection.IsSynchronized {
get {
return false;
}
}
object ICollection.SyncRoot {
get {
throw new NotSupportedException ();
}
}
#endregion
IEnumerable<TKey> IReadOnlyDictionary<TKey, TValue>.Keys {
get {
return Keys;
}
}
IEnumerable<TValue> IReadOnlyDictionary<TKey, TValue>.Values {
get {
return Values;
}
}
[Serializable]
[DebuggerDisplay ("Count={Count}")]
[DebuggerTypeProxy (typeof (CollectionDebuggerView<,>))]
public sealed class KeyCollection : ICollection<TKey>, IEnumerable<TKey>, ICollection, IEnumerable
{
readonly ICollection<TKey> collection;
internal KeyCollection (ICollection<TKey> collection)
{
this.collection = collection;
}
public void CopyTo (TKey [] array, int arrayIndex)
{
collection.CopyTo (array, arrayIndex);
}
public IEnumerator<TKey> GetEnumerator ()
{
return collection.GetEnumerator ();
}
void ICollection<TKey>.Add (TKey item)
{
throw new NotSupportedException ("this is a read-only collection");
}
void ICollection<TKey>.Clear ()
{
throw new NotSupportedException ("this is a read-only collection");
}
bool ICollection<TKey>.Contains (TKey item)
{
return collection.Contains (item);
}
bool ICollection<TKey>.Remove (TKey item)
{
throw new NotSupportedException ("this is a read-only collection");
}
void ICollection.CopyTo (Array array, int index)
{
var target = array as TKey [];
if (target != null) {
CopyTo (target, index);
return;
}
throw new NotImplementedException ();
}
IEnumerator IEnumerable.GetEnumerator ()
{
return collection.GetEnumerator ();
}
public int Count {
get {
return collection.Count;
}
}
bool ICollection<TKey>.IsReadOnly {
get {
return true;
}
}
bool ICollection.IsSynchronized {
get {
return false;
}
}
object ICollection.SyncRoot {
get {
throw new NotImplementedException ();
}
}
}
[Serializable]
[DebuggerDisplay ("Count={Count}")]
[DebuggerTypeProxy (typeof (CollectionDebuggerView<,>))]
public sealed class ValueCollection : ICollection<TValue>, IEnumerable<TValue>, ICollection, IEnumerable
{
readonly ICollection<TValue> collection;
internal ValueCollection (ICollection<TValue> collection)
{
this.collection = collection;
}
public void CopyTo (TValue [] array, int arrayIndex)
{
collection.CopyTo (array, arrayIndex);
}
public IEnumerator<TValue> GetEnumerator ()
{
return collection.GetEnumerator ();
}
void ICollection<TValue>.Add (TValue item)
{
throw new NotSupportedException ("this is a read-only collection");
}
void ICollection<TValue>.Clear ()
{
throw new NotSupportedException ("this is a read-only collection");
}
bool ICollection<TValue>.Contains (TValue item)
{
return collection.Contains (item);
}
bool ICollection<TValue>.Remove (TValue item)
{
throw new NotSupportedException ("this is a read-only collection");
}
void ICollection.CopyTo (Array array, int index)
{
var target = array as TValue [];
if (target != null) {
CopyTo (target, index);
return;
}
throw new NotImplementedException ();
}
IEnumerator IEnumerable.GetEnumerator ()
{
return collection.GetEnumerator ();
}
public int Count {
get {
return collection.Count;
}
}
bool ICollection<TValue>.IsReadOnly {
get {
return true;
}
}
bool ICollection.IsSynchronized {
get {
return false;
}
}
object ICollection.SyncRoot {
get {
throw new NotImplementedException ();
}
}
}
}
}
#endif