summaryrefslogtreecommitdiff
path: root/src/mscorlib/src/System/Collections
diff options
context:
space:
mode:
authorJiyoung Yun <jy910.yun@samsung.com>2017-06-13 09:47:36 (GMT)
committerJiyoung Yun <jy910.yun@samsung.com>2017-06-13 09:47:36 (GMT)
commit61d6a817e39d3bae0f47dbc09838d51db22a5d30 (patch)
treecb37caa1784bc738b976273335d6ed04a7cc80b0 /src/mscorlib/src/System/Collections
parent5b975f8233e8c8d17b215372f89ca713b45d6a0b (diff)
downloadcoreclr-61d6a817e39d3bae0f47dbc09838d51db22a5d30.zip
coreclr-61d6a817e39d3bae0f47dbc09838d51db22a5d30.tar.gz
coreclr-61d6a817e39d3bae0f47dbc09838d51db22a5d30.tar.bz2
Imported Upstream version 2.0.0.11992upstream/2.0.0.11992
Diffstat (limited to 'src/mscorlib/src/System/Collections')
-rw-r--r--src/mscorlib/src/System/Collections/ArrayList.cs626
-rw-r--r--src/mscorlib/src/System/Collections/Comparer.cs27
-rw-r--r--src/mscorlib/src/System/Collections/CompatibleComparer.cs1
-rw-r--r--src/mscorlib/src/System/Collections/Concurrent/ConcurrentQueue.cs1
-rw-r--r--src/mscorlib/src/System/Collections/EmptyReadOnlyDictionaryInternal.cs1
-rw-r--r--src/mscorlib/src/System/Collections/Generic/ArraySortHelper.cs1
-rw-r--r--src/mscorlib/src/System/Collections/Generic/Comparer.cs3
-rw-r--r--src/mscorlib/src/System/Collections/Generic/Dictionary.cs44
-rw-r--r--src/mscorlib/src/System/Collections/Generic/EqualityComparer.cs34
-rw-r--r--src/mscorlib/src/System/Collections/Generic/List.cs1
-rw-r--r--src/mscorlib/src/System/Collections/Hashtable.cs72
-rw-r--r--src/mscorlib/src/System/Collections/ObjectModel/ReadOnlyDictionary.cs4
12 files changed, 35 insertions, 780 deletions
diff --git a/src/mscorlib/src/System/Collections/ArrayList.cs b/src/mscorlib/src/System/Collections/ArrayList.cs
deleted file mode 100644
index cee7be7..0000000
--- a/src/mscorlib/src/System/Collections/ArrayList.cs
+++ /dev/null
@@ -1,626 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-/*============================================================
-**
-**
-**
-**
-**
-** Purpose: Implements a dynamically sized List as an array,
-** and provides many convenience methods for treating
-** an array as an IList.
-**
-**
-===========================================================*/
-
-using System;
-using System.Runtime;
-using System.Security;
-using System.Diagnostics;
-using System.Runtime.CompilerServices;
-using System.Runtime.Serialization;
-using System.Diagnostics.CodeAnalysis;
-using System.Diagnostics.Contracts;
-
-namespace System.Collections
-{
- // Implements a variable-size List that uses an array of objects to store the
- // elements. A ArrayList has a capacity, which is the allocated length
- // of the internal array. As elements are added to a ArrayList, the capacity
- // of the ArrayList is automatically increased as required by reallocating the
- // internal array.
- //
- [FriendAccessAllowed]
- [DebuggerTypeProxy(typeof(System.Collections.ArrayList.ArrayListDebugView))]
- [DebuggerDisplay("Count = {Count}")]
- [Serializable]
- internal class ArrayList : IList, ICloneable
- {
- private Object[] _items;
- [ContractPublicPropertyName("Count")]
- private int _size;
- private int _version;
- [NonSerialized]
- private Object _syncRoot;
-
- private const int _defaultCapacity = 4;
- private static readonly Object[] emptyArray = Array.Empty<Object>();
-
- // Constructs a ArrayList. The list is initially empty and has a capacity
- // of zero. Upon adding the first element to the list the capacity is
- // increased to _defaultCapacity, and then increased in multiples of two as required.
- public ArrayList()
- {
- _items = emptyArray;
- }
-
- // Constructs a ArrayList with a given initial capacity. The list is
- // initially empty, but will have room for the given number of elements
- // before any reallocations are required.
- //
- public ArrayList(int capacity)
- {
- if (capacity < 0) throw new ArgumentOutOfRangeException(nameof(capacity), SR.Format(SR.ArgumentOutOfRange_MustBeNonNegNum, nameof(capacity)));
- Contract.EndContractBlock();
-
- if (capacity == 0)
- _items = emptyArray;
- else
- _items = new Object[capacity];
- }
-
- // Constructs a ArrayList, copying the contents of the given collection. The
- // size and capacity of the new list will both be equal to the size of the
- // given collection.
- //
- public ArrayList(ICollection c)
- {
- if (c == null)
- throw new ArgumentNullException(nameof(c), SR.ArgumentNull_Collection);
- Contract.EndContractBlock();
-
- int count = c.Count;
- if (count == 0)
- {
- _items = emptyArray;
- }
- else
- {
- _items = new Object[count];
- AddRange(c);
- }
- }
-
- // Gets and sets the capacity of this list. The capacity is the size of
- // the internal array used to hold items. When set, the internal
- // array of the list is reallocated to the given capacity.
- //
- public virtual int Capacity
- {
- get
- {
- Contract.Ensures(Contract.Result<int>() >= Count);
- return _items.Length;
- }
- set
- {
- if (value < _size)
- {
- throw new ArgumentOutOfRangeException(nameof(value), SR.ArgumentOutOfRange_SmallCapacity);
- }
- Contract.Ensures(Capacity >= 0);
- Contract.EndContractBlock();
- // We don't want to update the version number when we change the capacity.
- // Some existing applications have dependency on this.
- if (value != _items.Length)
- {
- if (value > 0)
- {
- Object[] newItems = new Object[value];
- if (_size > 0)
- {
- Array.Copy(_items, 0, newItems, 0, _size);
- }
- _items = newItems;
- }
- else
- {
- _items = new Object[_defaultCapacity];
- }
- }
- }
- }
-
- // Read-only property describing how many elements are in the List.
- public virtual int Count
- {
- get
- {
- Contract.Ensures(Contract.Result<int>() >= 0);
- return _size;
- }
- }
-
- public virtual bool IsFixedSize
- {
- get { return false; }
- }
-
-
- // Is this ArrayList read-only?
- public virtual bool IsReadOnly
- {
- get { return false; }
- }
-
- // Is this ArrayList synchronized (thread-safe)?
- public virtual bool IsSynchronized
- {
- get { return false; }
- }
-
- // Synchronization root for this object.
- public virtual Object SyncRoot
- {
- get
- {
- if (_syncRoot == null)
- {
- System.Threading.Interlocked.CompareExchange<Object>(ref _syncRoot, new Object(), null);
- }
- return _syncRoot;
- }
- }
-
- // Sets or Gets the element at the given index.
- //
- public virtual Object this[int index]
- {
- get
- {
- if (index < 0 || index >= _size) throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index);
- Contract.EndContractBlock();
- return _items[index];
- }
- set
- {
- if (index < 0 || index >= _size) throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index);
- Contract.EndContractBlock();
- _items[index] = value;
- _version++;
- }
- }
-
- // Adds the given object to the end of this list. The size of the list is
- // increased by one. If required, the capacity of the list is doubled
- // before adding the new element.
- //
- public virtual int Add(Object value)
- {
- Contract.Ensures(Contract.Result<int>() >= 0);
- if (_size == _items.Length) EnsureCapacity(_size + 1);
- _items[_size] = value;
- _version++;
- return _size++;
- }
-
- // Adds the elements of the given collection to the end of this list. If
- // required, the capacity of the list is increased to twice the previous
- // capacity or the new size, whichever is larger.
- //
- public virtual void AddRange(ICollection c)
- {
- InsertRange(_size, c);
- }
-
-
- // Clears the contents of ArrayList.
- public virtual void Clear()
- {
- if (_size > 0)
- {
- Array.Clear(_items, 0, _size); // Don't need to doc this but we clear the elements so that the gc can reclaim the references.
- _size = 0;
- }
- _version++;
- }
-
- // Clones this ArrayList, doing a shallow copy. (A copy is made of all
- // Object references in the ArrayList, but the Objects pointed to
- // are not cloned).
- public virtual Object Clone()
- {
- Contract.Ensures(Contract.Result<Object>() != null);
- ArrayList la = new ArrayList(_size);
- la._size = _size;
- la._version = _version;
- Array.Copy(_items, 0, la._items, 0, _size);
- return la;
- }
-
-
- // Contains returns true if the specified element is in the ArrayList.
- // It does a linear, O(n) search. Equality is determined by calling
- // item.Equals().
- //
- public virtual bool Contains(Object item)
- {
- if (item == null)
- {
- for (int i = 0; i < _size; i++)
- if (_items[i] == null)
- return true;
- return false;
- }
- else
- {
- for (int i = 0; i < _size; i++)
- if ((_items[i] != null) && (_items[i].Equals(item)))
- return true;
- return false;
- }
- }
-
- // Copies this ArrayList into array, which must be of a
- // compatible array type.
- //
- public virtual void CopyTo(Array array, int arrayIndex)
- {
- if ((array != null) && (array.Rank != 1))
- throw new ArgumentException(SR.Arg_RankMultiDimNotSupported);
- Contract.EndContractBlock();
- // Delegate rest of error checking to Array.Copy.
- Array.Copy(_items, 0, array, arrayIndex, _size);
- }
-
- // Ensures that the capacity of this list is at least the given minimum
- // value. If the currect capacity of the list is less than min, the
- // capacity is increased to twice the current capacity or to min,
- // whichever is larger.
- private void EnsureCapacity(int min)
- {
- if (_items.Length < min)
- {
- int newCapacity = _items.Length == 0 ? _defaultCapacity : _items.Length * 2;
- // Allow the list to grow to maximum possible capacity (~2G elements) before encountering overflow.
- // Note that this check works even when _items.Length overflowed thanks to the (uint) cast
- if ((uint)newCapacity > Array.MaxArrayLength) newCapacity = Array.MaxArrayLength;
- if (newCapacity < min) newCapacity = min;
- Capacity = newCapacity;
- }
- }
-
- // Returns an enumerator for this list with the given
- // permission for removal of elements. If modifications made to the list
- // while an enumeration is in progress, the MoveNext and
- // GetObject methods of the enumerator will throw an exception.
- //
- public virtual IEnumerator GetEnumerator()
- {
- Contract.Ensures(Contract.Result<IEnumerator>() != null);
- return new ArrayListEnumeratorSimple(this);
- }
-
- // Returns the index of the first occurrence of a given value in a range of
- // this list. The list is searched forwards from beginning to end.
- // The elements of the list are compared to the given value using the
- // Object.Equals method.
- //
- // This method uses the Array.IndexOf method to perform the
- // search.
- //
- public virtual int IndexOf(Object value)
- {
- Contract.Ensures(Contract.Result<int>() < Count);
- return Array.IndexOf((Array)_items, value, 0, _size);
- }
-
- // Inserts an element into this list at a given index. The size of the list
- // is increased by one. If required, the capacity of the list is doubled
- // before inserting the new element.
- //
- public virtual void Insert(int index, Object value)
- {
- // Note that insertions at the end are legal.
- if (index < 0 || index > _size) throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_ArrayListInsert);
- //Contract.Ensures(Count == Contract.OldValue(Count) + 1);
- Contract.EndContractBlock();
-
- if (_size == _items.Length) EnsureCapacity(_size + 1);
- if (index < _size)
- {
- Array.Copy(_items, index, _items, index + 1, _size - index);
- }
- _items[index] = value;
- _size++;
- _version++;
- }
-
- // Inserts the elements of the given collection at a given index. If
- // required, the capacity of the list is increased to twice the previous
- // capacity or the new size, whichever is larger. Ranges may be added
- // to the end of the list by setting index to the ArrayList's size.
- //
- public virtual void InsertRange(int index, ICollection c)
- {
- if (c == null)
- throw new ArgumentNullException(nameof(c), SR.ArgumentNull_Collection);
- if (index < 0 || index > _size) throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index);
- //Contract.Ensures(Count == Contract.OldValue(Count) + c.Count);
- Contract.EndContractBlock();
-
- int count = c.Count;
- if (count > 0)
- {
- EnsureCapacity(_size + count);
- // shift existing items
- if (index < _size)
- {
- Array.Copy(_items, index, _items, index + count, _size - index);
- }
-
- Object[] itemsToInsert = new Object[count];
- c.CopyTo(itemsToInsert, 0);
- itemsToInsert.CopyTo(_items, index);
- _size += count;
- _version++;
- }
- }
-
- // Returns a read-only IList wrapper for the given IList.
- //
- [FriendAccessAllowed]
- public static IList ReadOnly(IList list)
- {
- if (list == null)
- throw new ArgumentNullException(nameof(list));
- Contract.Ensures(Contract.Result<IList>() != null);
- Contract.EndContractBlock();
- return new ReadOnlyList(list);
- }
-
- // Removes the element at the given index. The size of the list is
- // decreased by one.
- //
- public virtual void Remove(Object obj)
- {
- Contract.Ensures(Count >= 0);
-
- int index = IndexOf(obj);
- BCLDebug.Correctness(index >= 0 || !(obj is Int32), "You passed an Int32 to Remove that wasn't in the ArrayList." + Environment.NewLine + "Did you mean RemoveAt? int: " + obj + " Count: " + Count);
- if (index >= 0)
- RemoveAt(index);
- }
-
- // Removes the element at the given index. The size of the list is
- // decreased by one.
- //
- public virtual void RemoveAt(int index)
- {
- if (index < 0 || index >= _size) throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index);
- Contract.Ensures(Count >= 0);
- //Contract.Ensures(Count == Contract.OldValue(Count) - 1);
- Contract.EndContractBlock();
-
- _size--;
- if (index < _size)
- {
- Array.Copy(_items, index + 1, _items, index, _size - index);
- }
- _items[_size] = null;
- _version++;
- }
-
- // ToArray returns a new array of a particular type containing the contents
- // of the ArrayList. This requires copying the ArrayList and potentially
- // downcasting all elements. This copy may fail and is an O(n) operation.
- // Internally, this implementation calls Array.Copy.
- //
- public virtual Array ToArray(Type type)
- {
- if (type == null)
- throw new ArgumentNullException(nameof(type));
- Contract.Ensures(Contract.Result<Array>() != null);
- Contract.EndContractBlock();
- Array array = Array.UnsafeCreateInstance(type, _size);
- Array.Copy(_items, 0, array, 0, _size);
- return array;
- }
-
- [Serializable]
- private class ReadOnlyList : IList
- {
- private IList _list;
-
- internal ReadOnlyList(IList l)
- {
- _list = l;
- }
-
- public virtual int Count
- {
- get { return _list.Count; }
- }
-
- public virtual bool IsReadOnly
- {
- get { return true; }
- }
-
- public virtual bool IsFixedSize
- {
- get { return true; }
- }
-
- public virtual bool IsSynchronized
- {
- get { return _list.IsSynchronized; }
- }
-
- public virtual Object this[int index]
- {
- get
- {
- return _list[index];
- }
- set
- {
- throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
- }
- }
-
- public virtual Object SyncRoot
- {
- get { return _list.SyncRoot; }
- }
-
- public virtual int Add(Object obj)
- {
- throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
- }
-
- public virtual void Clear()
- {
- throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
- }
-
- public virtual bool Contains(Object obj)
- {
- return _list.Contains(obj);
- }
-
- public virtual void CopyTo(Array array, int index)
- {
- _list.CopyTo(array, index);
- }
-
- public virtual IEnumerator GetEnumerator()
- {
- return _list.GetEnumerator();
- }
-
- public virtual int IndexOf(Object value)
- {
- return _list.IndexOf(value);
- }
-
- public virtual void Insert(int index, Object obj)
- {
- throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
- }
-
- public virtual void Remove(Object value)
- {
- throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
- }
-
- public virtual void RemoveAt(int index)
- {
- throw new NotSupportedException(SR.NotSupported_ReadOnlyCollection);
- }
- }
-
- [Serializable]
- private sealed class ArrayListEnumeratorSimple : IEnumerator, ICloneable
- {
- private ArrayList list;
- private int index;
- private int version;
- private Object currentElement;
- [NonSerialized]
- private bool isArrayList;
- // this object is used to indicate enumeration has not started or has terminated
- private static Object dummyObject = new Object();
-
- internal ArrayListEnumeratorSimple(ArrayList list)
- {
- this.list = list;
- index = -1;
- version = list._version;
- isArrayList = (list.GetType() == typeof(ArrayList));
- currentElement = dummyObject;
- }
-
- public Object Clone()
- {
- return MemberwiseClone();
- }
-
- public bool MoveNext()
- {
- if (version != list._version)
- {
- throw new InvalidOperationException(SR.GetResourceString(ResId.InvalidOperation_EnumFailedVersion));
- }
-
- if (isArrayList)
- { // avoid calling virtual methods if we are operating on ArrayList to improve performance
- if (index < list._size - 1)
- {
- currentElement = list._items[++index];
- return true;
- }
- else
- {
- currentElement = dummyObject;
- index = list._size;
- return false;
- }
- }
- else
- {
- if (index < list.Count - 1)
- {
- currentElement = list[++index];
- return true;
- }
- else
- {
- index = list.Count;
- currentElement = dummyObject;
- return false;
- }
- }
- }
-
- public Object Current
- {
- get
- {
- object temp = currentElement;
- if (dummyObject == temp)
- { // check if enumeration has not started or has terminated
- if (index == -1)
- {
- throw new InvalidOperationException(SR.GetResourceString(ResId.InvalidOperation_EnumNotStarted));
- }
- else
- {
- throw new InvalidOperationException(SR.GetResourceString(ResId.InvalidOperation_EnumEnded));
- }
- }
-
- return temp;
- }
- }
-
- public void Reset()
- {
- if (version != list._version)
- {
- throw new InvalidOperationException(SR.GetResourceString(ResId.InvalidOperation_EnumFailedVersion));
- }
-
- currentElement = dummyObject;
- index = -1;
- }
- }
-
- internal class ArrayListDebugView
- {
- private ArrayList arrayList;
- }
- }
-}
diff --git a/src/mscorlib/src/System/Collections/Comparer.cs b/src/mscorlib/src/System/Collections/Comparer.cs
index 7f4f9f0..76e19e7 100644
--- a/src/mscorlib/src/System/Collections/Comparer.cs
+++ b/src/mscorlib/src/System/Collections/Comparer.cs
@@ -20,7 +20,6 @@ using System.Diagnostics.Contracts;
namespace System.Collections
{
- [Serializable]
internal sealed class Comparer : IComparer, ISerializable
{
private CompareInfo m_compareInfo;
@@ -44,21 +43,6 @@ namespace System.Collections
m_compareInfo = culture.CompareInfo;
}
- private Comparer(SerializationInfo info, StreamingContext context)
- {
- m_compareInfo = null;
- SerializationInfoEnumerator enumerator = info.GetEnumerator();
- while (enumerator.MoveNext())
- {
- switch (enumerator.Name)
- {
- case CompareInfoName:
- m_compareInfo = (CompareInfo)info.GetValue(CompareInfoName, typeof(CompareInfo));
- break;
- }
- }
- }
-
// Compares two Objects by calling CompareTo. If a ==
// b,0 is returned. If a implements
// IComparable, a.CompareTo(b) is returned. If a
@@ -92,16 +76,7 @@ namespace System.Collections
public void GetObjectData(SerializationInfo info, StreamingContext context)
{
- if (info == null)
- {
- throw new ArgumentNullException(nameof(info));
- }
- Contract.EndContractBlock();
-
- if (m_compareInfo != null)
- {
- info.AddValue(CompareInfoName, m_compareInfo);
- }
+ throw new PlatformNotSupportedException();
}
}
}
diff --git a/src/mscorlib/src/System/Collections/CompatibleComparer.cs b/src/mscorlib/src/System/Collections/CompatibleComparer.cs
index 1c90707..7dcaa4e 100644
--- a/src/mscorlib/src/System/Collections/CompatibleComparer.cs
+++ b/src/mscorlib/src/System/Collections/CompatibleComparer.cs
@@ -8,7 +8,6 @@ using System.Diagnostics.Contracts;
namespace System.Collections
{
- [Serializable]
internal class CompatibleComparer : IEqualityComparer
{
private IComparer _comparer;
diff --git a/src/mscorlib/src/System/Collections/Concurrent/ConcurrentQueue.cs b/src/mscorlib/src/System/Collections/Concurrent/ConcurrentQueue.cs
index c6211da..3540cca 100644
--- a/src/mscorlib/src/System/Collections/Concurrent/ConcurrentQueue.cs
+++ b/src/mscorlib/src/System/Collections/Concurrent/ConcurrentQueue.cs
@@ -20,7 +20,6 @@ namespace System.Collections.Concurrent
/// </remarks>
[DebuggerDisplay("Count = {Count}")]
[DebuggerTypeProxy(typeof(SystemCollectionsConcurrent_ProducerConsumerCollectionDebugView<>))]
- [Serializable]
internal class ConcurrentQueue<T> : IProducerConsumerCollection<T>, IReadOnlyCollection<T>
{
// This implementation provides an unbounded, multi-producer multi-consumer queue
diff --git a/src/mscorlib/src/System/Collections/EmptyReadOnlyDictionaryInternal.cs b/src/mscorlib/src/System/Collections/EmptyReadOnlyDictionaryInternal.cs
index 63e0d47..9841bdb 100644
--- a/src/mscorlib/src/System/Collections/EmptyReadOnlyDictionaryInternal.cs
+++ b/src/mscorlib/src/System/Collections/EmptyReadOnlyDictionaryInternal.cs
@@ -18,7 +18,6 @@ using System.Diagnostics.Contracts;
namespace System.Collections
{
/// This is a simple implementation of IDictionary that is empty and readonly.
- [Serializable]
internal sealed class EmptyReadOnlyDictionaryInternal : IDictionary
{
// Note that this class must be agile with respect to AppDomains. See its usage in
diff --git a/src/mscorlib/src/System/Collections/Generic/ArraySortHelper.cs b/src/mscorlib/src/System/Collections/Generic/ArraySortHelper.cs
index e313cda..e4a4acf 100644
--- a/src/mscorlib/src/System/Collections/Generic/ArraySortHelper.cs
+++ b/src/mscorlib/src/System/Collections/Generic/ArraySortHelper.cs
@@ -368,7 +368,6 @@ namespace System.Collections.Generic
}
}
- [Serializable()]
internal class GenericArraySortHelper<T>
: IArraySortHelper<T>
where T : IComparable<T>
diff --git a/src/mscorlib/src/System/Collections/Generic/Comparer.cs b/src/mscorlib/src/System/Collections/Generic/Comparer.cs
index a9b4b3f..e163faa 100644
--- a/src/mscorlib/src/System/Collections/Generic/Comparer.cs
+++ b/src/mscorlib/src/System/Collections/Generic/Comparer.cs
@@ -51,7 +51,6 @@ namespace System.Collections.Generic
// reasons. Adding another base class (even one with no fields)
// means another generic instantiation, which can be costly esp.
// for value types.
-
[Serializable]
internal sealed class GenericComparer<T> : Comparer<T> where T : IComparable<T>
{
@@ -112,7 +111,6 @@ namespace System.Collections.Generic
GetType().GetHashCode();
}
- [Serializable]
internal sealed class ComparisonComparer<T> : Comparer<T>
{
private readonly Comparison<T> _comparison;
@@ -133,7 +131,6 @@ namespace System.Collections.Generic
// and have a SerializationInfo/StreamingContext ctor,
// since we want to serialize as ObjectComparer for
// back-compat reasons (see below).
-
[Serializable]
internal sealed class Int32EnumComparer<T> : Comparer<T>, ISerializable where T : struct
{
diff --git a/src/mscorlib/src/System/Collections/Generic/Dictionary.cs b/src/mscorlib/src/System/Collections/Generic/Dictionary.cs
index e360eef..cd33428 100644
--- a/src/mscorlib/src/System/Collections/Generic/Dictionary.cs
+++ b/src/mscorlib/src/System/Collections/Generic/Dictionary.cs
@@ -17,29 +17,6 @@
** thread safety. If a reader writer lock is available, then that may be used
** with a Dictionary to get the same thread safety guarantee.
**
-** Reader writer locks don't exist in silverlight, so we do the following as a
-** result of removing non-generic collections from silverlight:
-** 1. If the Hashtable was fully synchronized, then we replace it with a
-** Dictionary with full locks around reads/writes (same thread safety
-** guarantee).
-** 2. Otherwise, the Hashtable has the default MR/SW thread safety behavior,
-** so we do one of the following on a case-by-case basis:
-** a. If the race condition can be addressed by rearranging the code and using a temp
-** variable (for example, it's only populated immediately after created)
-** then we address the race condition this way and use Dictionary.
-** b. If there's concern about degrading performance with the increased
-** locking, we ifdef with FEATURE_NONGENERIC_COLLECTIONS so we can at
-** least use Hashtable in the desktop build, but Dictionary with full
-** locks in silverlight builds. Note that this is heavier locking than
-** MR/SW, but this is the only option without rewriting (or adding back)
-** the reader writer lock.
-** c. If there's no performance concern (e.g. debug-only code) we
-** consistently replace Hashtable with Dictionary plus full locks to
-** reduce complexity.
-** d. Most of serialization is dead code in silverlight. Instead of updating
-** those Hashtable occurences in serialization, we carved out references
-** to serialization such that this code doesn't need to build in
-** silverlight.
===========================================================*/
namespace System.Collections.Generic
@@ -706,22 +683,6 @@ namespace System.Collections.Generic
value = default(TValue);
return false;
}
-
- // Method similar to TryGetValue that returns the value instead of putting it in an out param.
- public TValue GetValueOrDefault(TKey key) => GetValueOrDefault(key, default(TValue));
-
- // Method similar to TryGetValue that returns the value instead of putting it in an out param. If the entry
- // doesn't exist, returns the defaultValue instead.
- public TValue GetValueOrDefault(TKey key, TValue defaultValue)
- {
- int i = FindEntry(key);
- if (i >= 0)
- {
- return entries[i].value;
- }
- return defaultValue;
- }
-
public bool TryAdd(TKey key, TValue value) => TryInsert(key, value, InsertionBehavior.None);
bool ICollection<KeyValuePair<TKey, TValue>>.IsReadOnly
@@ -947,7 +908,6 @@ namespace System.Collections.Generic
}
}
- [Serializable]
public struct Enumerator : IEnumerator<KeyValuePair<TKey, TValue>>,
IDictionaryEnumerator
{
@@ -1076,7 +1036,6 @@ namespace System.Collections.Generic
[DebuggerTypeProxy(typeof(Mscorlib_DictionaryKeyCollectionDebugView<,>))]
[DebuggerDisplay("Count = {Count}")]
- [Serializable]
public sealed class KeyCollection : ICollection<TKey>, ICollection, IReadOnlyCollection<TKey>
{
private Dictionary<TKey, TValue> dictionary;
@@ -1227,7 +1186,6 @@ namespace System.Collections.Generic
get { return ((ICollection)dictionary).SyncRoot; }
}
- [Serializable]
public struct Enumerator : IEnumerator<TKey>, System.Collections.IEnumerator
{
private Dictionary<TKey, TValue> dictionary;
@@ -1306,7 +1264,6 @@ namespace System.Collections.Generic
[DebuggerTypeProxy(typeof(Mscorlib_DictionaryValueCollectionDebugView<,>))]
[DebuggerDisplay("Count = {Count}")]
- [Serializable]
public sealed class ValueCollection : ICollection<TValue>, ICollection, IReadOnlyCollection<TValue>
{
private Dictionary<TKey, TValue> dictionary;
@@ -1455,7 +1412,6 @@ namespace System.Collections.Generic
get { return ((ICollection)dictionary).SyncRoot; }
}
- [Serializable]
public struct Enumerator : IEnumerator<TValue>, System.Collections.IEnumerator
{
private Dictionary<TKey, TValue> dictionary;
diff --git a/src/mscorlib/src/System/Collections/Generic/EqualityComparer.cs b/src/mscorlib/src/System/Collections/Generic/EqualityComparer.cs
index 0cd1bc1..d6b213c 100644
--- a/src/mscorlib/src/System/Collections/Generic/EqualityComparer.cs
+++ b/src/mscorlib/src/System/Collections/Generic/EqualityComparer.cs
@@ -10,6 +10,7 @@ using System.Security;
using System.Globalization;
using System.Runtime;
using System.Runtime.CompilerServices;
+using System.Runtime.Serialization;
using System.Diagnostics.Contracts;
namespace System.Collections.Generic
@@ -352,7 +353,7 @@ namespace System.Collections.Generic
}
[Serializable]
- internal class EnumEqualityComparer<T> : EqualityComparer<T> where T : struct
+ internal class EnumEqualityComparer<T> : EqualityComparer<T>, ISerializable where T : struct
{
[Pure]
public override bool Equals(T x, T y)
@@ -371,6 +372,9 @@ namespace System.Collections.Generic
public EnumEqualityComparer() { }
+ // This is used by the serialization engine.
+ protected EnumEqualityComparer(SerializationInfo information, StreamingContext context) { }
+
// Equals method for the comparer itself.
public override bool Equals(Object obj) =>
obj != null && GetType() == obj.GetType();
@@ -401,6 +405,14 @@ namespace System.Collections.Generic
}
return -1;
}
+
+ public void GetObjectData(SerializationInfo info, StreamingContext context)
+ {
+ // For back-compat we need to serialize the comparers for enums with underlying types other than int as ObjectEqualityComparer
+ if (Type.GetTypeCode(Enum.GetUnderlyingType(typeof(T))) != TypeCode.Int32) {
+ info.SetType(typeof(ObjectEqualityComparer<T>));
+ }
+ }
}
[Serializable]
@@ -408,6 +420,9 @@ namespace System.Collections.Generic
{
public SByteEnumEqualityComparer() { }
+ // This is used by the serialization engine.
+ public SByteEnumEqualityComparer(SerializationInfo information, StreamingContext context) { }
+
[Pure]
public override int GetHashCode(T obj)
{
@@ -417,10 +432,13 @@ namespace System.Collections.Generic
}
[Serializable]
- internal sealed class ShortEnumEqualityComparer<T> : EnumEqualityComparer<T> where T : struct
+ internal sealed class ShortEnumEqualityComparer<T> : EnumEqualityComparer<T>, ISerializable where T : struct
{
public ShortEnumEqualityComparer() { }
+ // This is used by the serialization engine.
+ public ShortEnumEqualityComparer(SerializationInfo information, StreamingContext context) { }
+
[Pure]
public override int GetHashCode(T obj)
{
@@ -430,7 +448,7 @@ namespace System.Collections.Generic
}
[Serializable]
- internal sealed class LongEnumEqualityComparer<T> : EqualityComparer<T> where T : struct
+ internal sealed class LongEnumEqualityComparer<T> : EqualityComparer<T>, ISerializable where T : struct
{
[Pure]
public override bool Equals(T x, T y)
@@ -479,5 +497,15 @@ namespace System.Collections.Generic
}
return -1;
}
+
+ // This is used by the serialization engine.
+ public LongEnumEqualityComparer(SerializationInfo information, StreamingContext context) { }
+
+ public void GetObjectData(SerializationInfo info, StreamingContext context)
+ {
+ // The LongEnumEqualityComparer does not exist on 4.0 so we need to serialize this comparer as ObjectEqualityComparer
+ // to allow for roundtrip between 4.0 and 4.5.
+ info.SetType(typeof(ObjectEqualityComparer<T>));
+ }
}
}
diff --git a/src/mscorlib/src/System/Collections/Generic/List.cs b/src/mscorlib/src/System/Collections/Generic/List.cs
index 4e48088..94e794c 100644
--- a/src/mscorlib/src/System/Collections/Generic/List.cs
+++ b/src/mscorlib/src/System/Collections/Generic/List.cs
@@ -1254,7 +1254,6 @@ namespace System.Collections.Generic
}
}
- [Serializable]
public struct Enumerator : IEnumerator<T>, System.Collections.IEnumerator
{
private List<T> list;
diff --git a/src/mscorlib/src/System/Collections/Hashtable.cs b/src/mscorlib/src/System/Collections/Hashtable.cs
index e2fd57e..0c89632 100644
--- a/src/mscorlib/src/System/Collections/Hashtable.cs
+++ b/src/mscorlib/src/System/Collections/Hashtable.cs
@@ -66,7 +66,6 @@ namespace System.Collections
//
[DebuggerTypeProxy(typeof(System.Collections.Hashtable.HashtableDebugView))]
[DebuggerDisplay("Count = {Count}")]
- [Serializable]
internal class Hashtable : IDictionary, ISerializable, IDeserializationCallback, ICloneable
{
/*
@@ -919,58 +918,7 @@ namespace System.Collections
public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
{
- if (info == null)
- {
- throw new ArgumentNullException(nameof(info));
- }
- Contract.EndContractBlock();
- // This is imperfect - it only works well if all other writes are
- // also using our synchronized wrapper. But it's still a good idea.
- lock (SyncRoot)
- {
- // This method hasn't been fully tweaked to be safe for a concurrent writer.
- int oldVersion = version;
- info.AddValue(LoadFactorName, loadFactor);
- info.AddValue(VersionName, version);
-
- //
- // We need to maintain serialization compatibility with Everett and RTM.
- // If the comparer is null or a compatible comparer, serialize Hashtable
- // in a format that can be deserialized on Everett and RTM.
- //
-#pragma warning disable 618
- IEqualityComparer keyComparerForSerilization = _keycomparer;
-
- if (keyComparerForSerilization == null)
- {
- info.AddValue(ComparerName, null, typeof(IComparer));
- info.AddValue(HashCodeProviderName, null, typeof(IHashCodeProvider));
- }
- else if (keyComparerForSerilization is CompatibleComparer)
- {
- CompatibleComparer c = keyComparerForSerilization as CompatibleComparer;
- info.AddValue(ComparerName, c.Comparer, typeof(IComparer));
- info.AddValue(HashCodeProviderName, c.HashCodeProvider, typeof(IHashCodeProvider));
- }
- else
- {
- info.AddValue(KeyComparerName, keyComparerForSerilization, typeof(IEqualityComparer));
- }
-#pragma warning restore 618
-
- info.AddValue(HashSizeName, buckets.Length); //This is the length of the bucket array.
- Object[] serKeys = new Object[count];
- Object[] serValues = new Object[count];
- CopyKeys(serKeys, 0);
- CopyValues(serValues, 0);
- info.AddValue(KeysName, serKeys, typeof(Object[]));
- info.AddValue(ValuesName, serValues, typeof(Object[]));
-
- // Explicitly check to see if anyone changed the Hashtable while we
- // were serializing it. That's a race condition in their code.
- if (version != oldVersion)
- throw new InvalidOperationException(SR.GetResourceString(ResId.InvalidOperation_EnumFailedVersion));
- }
+ throw new PlatformNotSupportedException();
}
//
@@ -1073,7 +1021,6 @@ namespace System.Collections
// Implements a Collection for the keys of a hashtable. An instance of this
// class is created by the GetKeys method of a hashtable.
- [Serializable]
private class KeyCollection : ICollection
{
private Hashtable _hashtable;
@@ -1120,7 +1067,6 @@ namespace System.Collections
// Implements a Collection for the values of a hashtable. An instance of
// this class is created by the GetValues method of a hashtable.
- [Serializable]
private class ValueCollection : ICollection
{
private Hashtable _hashtable;
@@ -1166,7 +1112,6 @@ namespace System.Collections
}
// Synchronized wrapper for hashtable
- [Serializable]
private class SyncHashtable : Hashtable, IEnumerable
{
protected Hashtable _table;
@@ -1189,17 +1134,7 @@ namespace System.Collections
==============================================================================*/
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
- if (info == null)
- {
- throw new ArgumentNullException(nameof(info));
- }
- Contract.EndContractBlock();
- // Our serialization code hasn't been fully tweaked to be safe
- // for a concurrent writer.
- lock (_table.SyncRoot)
- {
- info.AddValue("ParentTable", _table, typeof(Hashtable));
- }
+ throw new PlatformNotSupportedException();
}
public override int Count
@@ -1339,7 +1274,7 @@ namespace System.Collections
==============================================================================*/
public override void OnDeserialization(Object sender)
{
- return;
+ throw new PlatformNotSupportedException();
}
}
@@ -1347,7 +1282,6 @@ namespace System.Collections
// Implements an enumerator for a hashtable. The enumerator uses the
// internal version number of the hashtabke to ensure that no modifications
// are made to the hashtable while an enumeration is in progress.
- [Serializable]
private class HashtableEnumerator : IDictionaryEnumerator, ICloneable
{
private Hashtable hashtable;
diff --git a/src/mscorlib/src/System/Collections/ObjectModel/ReadOnlyDictionary.cs b/src/mscorlib/src/System/Collections/ObjectModel/ReadOnlyDictionary.cs
index ebf86cd..3fd0cf8 100644
--- a/src/mscorlib/src/System/Collections/ObjectModel/ReadOnlyDictionary.cs
+++ b/src/mscorlib/src/System/Collections/ObjectModel/ReadOnlyDictionary.cs
@@ -19,7 +19,6 @@ using System.Diagnostics.Contracts;
namespace System.Collections.ObjectModel
{
- [Serializable]
[DebuggerTypeProxy(typeof(Mscorlib_DictionaryDebugView<,>))]
[DebuggerDisplay("Count = {Count}")]
internal class ReadOnlyDictionary<TKey, TValue> : IDictionary<TKey, TValue>, IDictionary, IReadOnlyDictionary<TKey, TValue>
@@ -365,7 +364,6 @@ namespace System.Collections.ObjectModel
}
}
- [Serializable]
private struct DictionaryEnumerator : IDictionaryEnumerator
{
private readonly IDictionary<TKey, TValue> m_dictionary;
@@ -432,7 +430,6 @@ namespace System.Collections.ObjectModel
[DebuggerTypeProxy(typeof(Mscorlib_CollectionDebugView<>))]
[DebuggerDisplay("Count = {Count}")]
- [Serializable]
public sealed class KeyCollection : ICollection<TKey>, ICollection, IReadOnlyCollection<TKey>
{
private readonly ICollection<TKey> m_collection;
@@ -543,7 +540,6 @@ namespace System.Collections.ObjectModel
[DebuggerTypeProxy(typeof(Mscorlib_CollectionDebugView<>))]
[DebuggerDisplay("Count = {Count}")]
- [Serializable]
public sealed class ValueCollection : ICollection<TValue>, ICollection, IReadOnlyCollection<TValue>
{
private readonly ICollection<TValue> m_collection;