summaryrefslogtreecommitdiff
path: root/src/mscorlib/shared/System/Collections/Generic
diff options
context:
space:
mode:
Diffstat (limited to 'src/mscorlib/shared/System/Collections/Generic')
-rw-r--r--src/mscorlib/shared/System/Collections/Generic/ICollection.cs35
-rw-r--r--src/mscorlib/shared/System/Collections/Generic/IComparer.cs20
-rw-r--r--src/mscorlib/shared/System/Collections/Generic/IDictionary.cs51
-rw-r--r--src/mscorlib/shared/System/Collections/Generic/IEnumerable.cs21
-rw-r--r--src/mscorlib/shared/System/Collections/Generic/IEnumerator.cs26
-rw-r--r--src/mscorlib/shared/System/Collections/Generic/IEqualityComparer.cs18
-rw-r--r--src/mscorlib/shared/System/Collections/Generic/IList.cs37
-rw-r--r--src/mscorlib/shared/System/Collections/Generic/IReadOnlyCollection.cs16
-rw-r--r--src/mscorlib/shared/System/Collections/Generic/IReadOnlyDictionary.cs20
-rw-r--r--src/mscorlib/shared/System/Collections/Generic/IReadOnlyList.cs16
-rw-r--r--src/mscorlib/shared/System/Collections/Generic/KeyNotFoundException.cs33
-rw-r--r--src/mscorlib/shared/System/Collections/Generic/KeyValuePair.cs82
12 files changed, 375 insertions, 0 deletions
diff --git a/src/mscorlib/shared/System/Collections/Generic/ICollection.cs b/src/mscorlib/shared/System/Collections/Generic/ICollection.cs
new file mode 100644
index 0000000000..52852aa1fb
--- /dev/null
+++ b/src/mscorlib/shared/System/Collections/Generic/ICollection.cs
@@ -0,0 +1,35 @@
+// 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.
+
+using System;
+using System.Runtime.CompilerServices;
+using System.Diagnostics.Contracts;
+
+namespace System.Collections.Generic
+{
+ // Base interface for all collections, defining enumerators, size, and
+ // synchronization methods.
+ public interface ICollection<T> : IEnumerable<T>
+ {
+ // Number of items in the collections.
+ int Count { get; }
+
+ bool IsReadOnly { get; }
+
+ void Add(T item);
+
+ void Clear();
+
+ bool Contains(T item);
+
+ // CopyTo copies a collection into an Array, starting at a particular
+ // index into the array.
+ //
+ void CopyTo(T[] array, int arrayIndex);
+
+ //void CopyTo(int sourceIndex, T[] destinationArray, int destinationIndex, int count);
+
+ bool Remove(T item);
+ }
+}
diff --git a/src/mscorlib/shared/System/Collections/Generic/IComparer.cs b/src/mscorlib/shared/System/Collections/Generic/IComparer.cs
new file mode 100644
index 0000000000..713d499cc8
--- /dev/null
+++ b/src/mscorlib/shared/System/Collections/Generic/IComparer.cs
@@ -0,0 +1,20 @@
+// 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.
+
+using System;
+
+namespace System.Collections.Generic
+{
+ // The generic IComparer interface implements a method that compares
+ // two objects. It is used in conjunction with the Sort and
+ // BinarySearch methods on the Array, List, and SortedList classes.
+ public interface IComparer<in T>
+ {
+ // Compares two objects. An implementation of this method must return a
+ // value less than zero if x is less than y, zero if x is equal to y, or a
+ // value greater than zero if x is greater than y.
+ //
+ int Compare(T x, T y);
+ }
+}
diff --git a/src/mscorlib/shared/System/Collections/Generic/IDictionary.cs b/src/mscorlib/shared/System/Collections/Generic/IDictionary.cs
new file mode 100644
index 0000000000..a73a2f55bd
--- /dev/null
+++ b/src/mscorlib/shared/System/Collections/Generic/IDictionary.cs
@@ -0,0 +1,51 @@
+// 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.
+
+using System;
+using System.Diagnostics.Contracts;
+
+namespace System.Collections.Generic
+{
+ // An IDictionary is a possibly unordered set of key-value pairs.
+ // Keys can be any non-null object. Values can be any object.
+ // You can look up a value in an IDictionary via the default indexed
+ // property, Items.
+ public interface IDictionary<TKey, TValue> : ICollection<KeyValuePair<TKey, TValue>>
+ {
+ // Interfaces are not serializable
+ // The Item property provides methods to read and edit entries
+ // in the Dictionary.
+ TValue this[TKey key]
+ {
+ get;
+ set;
+ }
+
+ // Returns a collections of the keys in this dictionary.
+ ICollection<TKey> Keys
+ {
+ get;
+ }
+
+ // Returns a collections of the values in this dictionary.
+ ICollection<TValue> Values
+ {
+ get;
+ }
+
+ // Returns whether this dictionary contains a particular key.
+ //
+ bool ContainsKey(TKey key);
+
+ // Adds a key-value pair to the dictionary.
+ //
+ void Add(TKey key, TValue value);
+
+ // Removes a particular key from the dictionary.
+ //
+ bool Remove(TKey key);
+
+ bool TryGetValue(TKey key, out TValue value);
+ }
+}
diff --git a/src/mscorlib/shared/System/Collections/Generic/IEnumerable.cs b/src/mscorlib/shared/System/Collections/Generic/IEnumerable.cs
new file mode 100644
index 0000000000..84264d5cf0
--- /dev/null
+++ b/src/mscorlib/shared/System/Collections/Generic/IEnumerable.cs
@@ -0,0 +1,21 @@
+// 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.
+
+using System;
+using System.Collections;
+using System.Runtime.InteropServices;
+using System.Runtime.CompilerServices;
+using System.Diagnostics.Contracts;
+
+namespace System.Collections.Generic
+{
+ // Implement this interface if you need to support foreach semantics.
+ public interface IEnumerable<out T> : IEnumerable
+ {
+ // Returns an IEnumerator for this enumerable Object. The enumerator provides
+ // a simple way to access all the contents of a collection.
+ /// <include file='doc\IEnumerable.uex' path='docs/doc[@for="IEnumerable.GetEnumerator"]/*' />
+ new IEnumerator<T> GetEnumerator();
+ }
+}
diff --git a/src/mscorlib/shared/System/Collections/Generic/IEnumerator.cs b/src/mscorlib/shared/System/Collections/Generic/IEnumerator.cs
new file mode 100644
index 0000000000..6360576974
--- /dev/null
+++ b/src/mscorlib/shared/System/Collections/Generic/IEnumerator.cs
@@ -0,0 +1,26 @@
+// 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.
+
+using System;
+using System.Runtime.InteropServices;
+
+namespace System.Collections.Generic
+{
+ // Base interface for all generic enumerators, providing a simple approach
+ // to iterating over a collection.
+ public interface IEnumerator<out T> : IDisposable, IEnumerator
+ {
+ // Returns the current element of the enumeration. The returned value is
+ // undefined before the first call to MoveNext and following a
+ // call to MoveNext that returned false. Multiple calls to
+ // GetCurrent with no intervening calls to MoveNext
+ // will return the same object.
+ //
+ /// <include file='doc\IEnumerator.uex' path='docs/doc[@for="IEnumerator.Current"]/*' />
+ new T Current
+ {
+ get;
+ }
+ }
+}
diff --git a/src/mscorlib/shared/System/Collections/Generic/IEqualityComparer.cs b/src/mscorlib/shared/System/Collections/Generic/IEqualityComparer.cs
new file mode 100644
index 0000000000..543bdb5fce
--- /dev/null
+++ b/src/mscorlib/shared/System/Collections/Generic/IEqualityComparer.cs
@@ -0,0 +1,18 @@
+// 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.
+
+using System;
+
+namespace System.Collections.Generic
+{
+ // The generic IEqualityComparer interface implements methods to if check two objects are equal
+ // and generate Hashcode for an object.
+ // It is use in Dictionary class.
+ public interface IEqualityComparer<in T>
+ {
+ bool Equals(T x, T y);
+ int GetHashCode(T obj);
+ }
+}
+
diff --git a/src/mscorlib/shared/System/Collections/Generic/IList.cs b/src/mscorlib/shared/System/Collections/Generic/IList.cs
new file mode 100644
index 0000000000..43d6659da9
--- /dev/null
+++ b/src/mscorlib/shared/System/Collections/Generic/IList.cs
@@ -0,0 +1,37 @@
+// 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.
+
+using System;
+using System.Collections;
+using System.Runtime.CompilerServices;
+using System.Diagnostics.Contracts;
+
+namespace System.Collections.Generic
+{
+ // An IList is an ordered collection of objects. The exact ordering
+ // is up to the implementation of the list, ranging from a sorted
+ // order to insertion order.
+ public interface IList<T> : ICollection<T>
+ {
+ // The Item property provides methods to read and edit entries in the List.
+ T this[int index]
+ {
+ get;
+ set;
+ }
+
+ // Returns the index of a particular item, if it is in the list.
+ // Returns -1 if the item isn't in the list.
+ int IndexOf(T item);
+
+ // Inserts value into the list at position index.
+ // index must be non-negative and less than or equal to the
+ // number of elements in the list. If index equals the number
+ // of items in the list, then value is appended to the end.
+ void Insert(int index, T item);
+
+ // Removes the item at position index.
+ void RemoveAt(int index);
+ }
+}
diff --git a/src/mscorlib/shared/System/Collections/Generic/IReadOnlyCollection.cs b/src/mscorlib/shared/System/Collections/Generic/IReadOnlyCollection.cs
new file mode 100644
index 0000000000..09ee89f035
--- /dev/null
+++ b/src/mscorlib/shared/System/Collections/Generic/IReadOnlyCollection.cs
@@ -0,0 +1,16 @@
+// 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.
+
+using System;
+using System.Diagnostics.Contracts;
+using System.Runtime.CompilerServices;
+
+namespace System.Collections.Generic
+{
+ // Provides a read-only, covariant view of a generic list.
+ public interface IReadOnlyCollection<out T> : IEnumerable<T>
+ {
+ int Count { get; }
+ }
+}
diff --git a/src/mscorlib/shared/System/Collections/Generic/IReadOnlyDictionary.cs b/src/mscorlib/shared/System/Collections/Generic/IReadOnlyDictionary.cs
new file mode 100644
index 0000000000..169e2958bb
--- /dev/null
+++ b/src/mscorlib/shared/System/Collections/Generic/IReadOnlyDictionary.cs
@@ -0,0 +1,20 @@
+// 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.
+
+using System;
+using System.Diagnostics.Contracts;
+
+namespace System.Collections.Generic
+{
+ // Provides a read-only view of a generic dictionary.
+ public interface IReadOnlyDictionary<TKey, TValue> : IReadOnlyCollection<KeyValuePair<TKey, TValue>>
+ {
+ bool ContainsKey(TKey key);
+ bool TryGetValue(TKey key, out TValue value);
+
+ TValue this[TKey key] { get; }
+ IEnumerable<TKey> Keys { get; }
+ IEnumerable<TValue> Values { get; }
+ }
+}
diff --git a/src/mscorlib/shared/System/Collections/Generic/IReadOnlyList.cs b/src/mscorlib/shared/System/Collections/Generic/IReadOnlyList.cs
new file mode 100644
index 0000000000..00b5be65ff
--- /dev/null
+++ b/src/mscorlib/shared/System/Collections/Generic/IReadOnlyList.cs
@@ -0,0 +1,16 @@
+// 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.
+
+using System;
+using System.Diagnostics.Contracts;
+using System.Runtime.CompilerServices;
+
+namespace System.Collections.Generic
+{
+ // Provides a read-only, covariant view of a generic list.
+ public interface IReadOnlyList<out T> : IReadOnlyCollection<T>
+ {
+ T this[int index] { get; }
+ }
+}
diff --git a/src/mscorlib/shared/System/Collections/Generic/KeyNotFoundException.cs b/src/mscorlib/shared/System/Collections/Generic/KeyNotFoundException.cs
new file mode 100644
index 0000000000..1fca7732ae
--- /dev/null
+++ b/src/mscorlib/shared/System/Collections/Generic/KeyNotFoundException.cs
@@ -0,0 +1,33 @@
+// 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.
+
+using System;
+using System.Runtime.Serialization;
+
+namespace System.Collections.Generic
+{
+ [Serializable]
+ public class KeyNotFoundException : SystemException
+ {
+ public KeyNotFoundException()
+ : base(SR.Arg_KeyNotFound)
+ {
+ HResult = __HResults.COR_E_KEYNOTFOUND;
+ }
+
+ public KeyNotFoundException(String message)
+ : base(message)
+ {
+ HResult = __HResults.COR_E_KEYNOTFOUND;
+ }
+
+ public KeyNotFoundException(String message, Exception innerException)
+ : base(message, innerException)
+ {
+ HResult = __HResults.COR_E_KEYNOTFOUND;
+ }
+
+ protected KeyNotFoundException(SerializationInfo info, StreamingContext context) : base(info, context) { }
+ }
+}
diff --git a/src/mscorlib/shared/System/Collections/Generic/KeyValuePair.cs b/src/mscorlib/shared/System/Collections/Generic/KeyValuePair.cs
new file mode 100644
index 0000000000..fc51af25f8
--- /dev/null
+++ b/src/mscorlib/shared/System/Collections/Generic/KeyValuePair.cs
@@ -0,0 +1,82 @@
+// 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.
+
+using System.ComponentModel;
+using System.Text;
+
+namespace System.Collections.Generic
+{
+ // Provides the Create factory method for KeyValuePair<TKey, TValue>.
+ public static class KeyValuePair
+ {
+ // Creates a new KeyValuePair<TKey, TValue> from the given values.
+ public static KeyValuePair<TKey, TValue> Create<TKey, TValue>(TKey key, TValue value)
+ {
+ return new KeyValuePair<TKey, TValue>(key, value);
+ }
+
+ /// <summary>
+ /// Used by KeyValuePair.ToString to reduce generic code
+ /// </summary>
+ internal static string PairToString(object key, object value)
+ {
+ StringBuilder s = StringBuilderCache.Acquire();
+ s.Append('[');
+
+ if (key != null)
+ {
+ s.Append(key);
+ }
+
+ s.Append(", ");
+
+ if (value != null)
+ {
+ s.Append(value);
+ }
+
+ s.Append(']');
+
+ return StringBuilderCache.GetStringAndRelease(s);
+ }
+ }
+
+ // A KeyValuePair holds a key and a value from a dictionary.
+ // It is used by the IEnumerable<T> implementation for both IDictionary<TKey, TValue>
+ // and IReadOnlyDictionary<TKey, TValue>.
+ [Serializable]
+ public struct KeyValuePair<TKey, TValue>
+ {
+ private TKey key; // DO NOT change the field name, it's required for compatibility with desktop .NET as it appears in serialization payload.
+ private TValue value; // DO NOT change the field name, it's required for compatibility with desktop .NET as it appears in serialization payload.
+
+ public KeyValuePair(TKey key, TValue value)
+ {
+ this.key = key;
+ this.value = value;
+ }
+
+ public TKey Key
+ {
+ get { return key; }
+ }
+
+ public TValue Value
+ {
+ get { return value; }
+ }
+
+ public override string ToString()
+ {
+ return KeyValuePair.PairToString(Key, Value);
+ }
+
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public void Deconstruct(out TKey key, out TValue value)
+ {
+ key = Key;
+ value = Value;
+ }
+ }
+}