Imported Upstream version 4.0.0~alpha1

Former-commit-id: 806294f5ded97629b74c85c09952f2a74fe182d9
This commit is contained in:
Jo Shields
2015-04-07 09:35:12 +01:00
parent 283343f570
commit 3c1f479b9d
22469 changed files with 2931443 additions and 869343 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,169 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
// <OWNER>[....]</OWNER>
//
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
//using System.Globalization;
using System.Runtime.CompilerServices;
namespace System.Collections.Generic
{
[Serializable]
[TypeDependencyAttribute("System.Collections.Generic.ObjectComparer`1")]
public abstract class Comparer<T> : IComparer, IComparer<T>
{
static volatile Comparer<T> defaultComparer;
public static Comparer<T> Default {
get {
Contract.Ensures(Contract.Result<Comparer<T>>() != null);
Comparer<T> comparer = defaultComparer;
if (comparer == null) {
comparer = CreateComparer();
defaultComparer = comparer;
}
return comparer;
}
}
public static Comparer<T> Create(Comparison<T> comparison)
{
Contract.Ensures(Contract.Result<Comparer<T>>() != null);
if (comparison == null)
throw new ArgumentNullException("comparison");
return new ComparisonComparer<T>(comparison);
}
//
// Note that logic in this method is replicated in vm\compile.cpp to ensure that NGen
// saves the right instantiations
//
[System.Security.SecuritySafeCritical] // auto-generated
private static Comparer<T> CreateComparer() {
RuntimeType t = (RuntimeType)typeof(T);
// If T implements IComparable<T> return a GenericComparer<T>
#if FEATURE_LEGACYNETCF
// Pre-Apollo Windows Phone call the overload that sorts the keys, not values this achieves the same result
if (CompatibilitySwitches.IsAppEarlierThanWindowsPhone8) {
if (t.ImplementInterface(typeof(IComparable<T>))) {
return (Comparer<T>)RuntimeTypeHandle.CreateInstanceForAnotherGenericParameter((RuntimeType)typeof(GenericComparer<int>), t);
}
}
else
#endif
if (typeof(IComparable<T>).IsAssignableFrom(t)) {
return (Comparer<T>)RuntimeTypeHandle.CreateInstanceForAnotherGenericParameter((RuntimeType)typeof(GenericComparer<int>), t);
}
// If T is a Nullable<U> where U implements IComparable<U> return a NullableComparer<U>
if (t.IsGenericType && t.GetGenericTypeDefinition() == typeof(Nullable<>)) {
RuntimeType u = (RuntimeType)t.GetGenericArguments()[0];
if (typeof(IComparable<>).MakeGenericType(u).IsAssignableFrom(u)) {
return (Comparer<T>)RuntimeTypeHandle.CreateInstanceForAnotherGenericParameter((RuntimeType)typeof(NullableComparer<int>), u);
}
}
// Otherwise return an ObjectComparer<T>
return new ObjectComparer<T>();
}
public abstract int Compare(T x, T y);
int IComparer.Compare(object x, object y) {
if (x == null) return y == null ? 0 : -1;
if (y == null) return 1;
if (x is T && y is T) return Compare((T)x, (T)y);
ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidArgumentForComparison);
return 0;
}
}
[Serializable]
internal class GenericComparer<T> : Comparer<T> where T: IComparable<T>
{
public override int Compare(T x, T y) {
if (x != null) {
if (y != null) return x.CompareTo(y);
return 1;
}
if (y != null) return -1;
return 0;
}
// Equals method for the comparer itself.
public override bool Equals(Object obj){
GenericComparer<T> comparer = obj as GenericComparer<T>;
return comparer != null;
}
public override int GetHashCode() {
return this.GetType().Name.GetHashCode();
}
}
[Serializable]
internal class NullableComparer<T> : Comparer<Nullable<T>> where T : struct, IComparable<T>
{
public override int Compare(Nullable<T> x, Nullable<T> y) {
if (x.HasValue) {
if (y.HasValue) return x.value.CompareTo(y.value);
return 1;
}
if (y.HasValue) return -1;
return 0;
}
// Equals method for the comparer itself.
public override bool Equals(Object obj){
NullableComparer<T> comparer = obj as NullableComparer<T>;
return comparer != null;
}
public override int GetHashCode() {
return this.GetType().Name.GetHashCode();
}
}
[Serializable]
internal class ObjectComparer<T> : Comparer<T>
{
public override int Compare(T x, T y) {
return System.Collections.Comparer.Default.Compare(x, y);
}
// Equals method for the comparer itself.
public override bool Equals(Object obj){
ObjectComparer<T> comparer = obj as ObjectComparer<T>;
return comparer != null;
}
public override int GetHashCode() {
return this.GetType().Name.GetHashCode();
}
}
[Serializable]
internal class ComparisonComparer<T> : Comparer<T>
{
private readonly Comparison<T> _comparison;
public ComparisonComparer(Comparison<T> comparison) {
_comparison = comparison;
}
public override int Compare(T x, T y) {
return _comparison(x, y);
}
}
}

View File

@@ -0,0 +1,130 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
/*=============================================================================
**
**
**
** Purpose: DebugView class for generic collections
**
** <OWNER>[....]</OWNER>
**
**
=============================================================================*/
namespace System.Collections.Generic {
using System;
using System.Collections.ObjectModel;
using System.Security.Permissions;
using System.Diagnostics;
using System.Diagnostics.Contracts;
//
// VS IDE can't differentiate between types with the same name from different
// assembly. So we need to use different names for collection debug view for
// collections in mscorlib.dll and system.dll.
//
internal sealed class Mscorlib_CollectionDebugView<T> {
private ICollection<T> collection;
public Mscorlib_CollectionDebugView(ICollection<T> collection) {
if (collection == null)
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.collection);
this.collection = collection;
}
[DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
public T[] Items {
get {
T[] items = new T[collection.Count];
collection.CopyTo(items, 0);
return items;
}
}
}
internal sealed class Mscorlib_DictionaryKeyCollectionDebugView<TKey, TValue> {
private ICollection<TKey> collection;
public Mscorlib_DictionaryKeyCollectionDebugView(ICollection<TKey> collection) {
if (collection == null)
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.collection);
this.collection = collection;
}
[DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
public TKey[] Items {
get {
TKey[] items = new TKey[collection.Count];
collection.CopyTo(items, 0);
return items;
}
}
}
internal sealed class Mscorlib_DictionaryValueCollectionDebugView<TKey, TValue> {
private ICollection<TValue> collection;
public Mscorlib_DictionaryValueCollectionDebugView(ICollection<TValue> collection) {
if (collection == null)
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.collection);
this.collection = collection;
}
[DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
public TValue[] Items {
get {
TValue[] items = new TValue[collection.Count];
collection.CopyTo(items, 0);
return items;
}
}
}
internal sealed class Mscorlib_DictionaryDebugView<K, V> {
private IDictionary<K, V> dict;
public Mscorlib_DictionaryDebugView(IDictionary<K, V> dictionary) {
if (dictionary == null)
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.dictionary);
this.dict = dictionary;
}
[DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
public KeyValuePair<K, V>[] Items {
get {
KeyValuePair<K, V>[] items = new KeyValuePair<K, V>[dict.Count];
dict.CopyTo(items, 0);
return items;
}
}
}
internal sealed class Mscorlib_KeyedCollectionDebugView<K, T> {
private KeyedCollection<K, T> kc;
public Mscorlib_KeyedCollectionDebugView(KeyedCollection<K, T> keyedCollection) {
if (keyedCollection == null) {
throw new ArgumentNullException("keyedCollection");
}
Contract.EndContractBlock();
kc = keyedCollection;
}
[DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
public T[] Items {
get {
T[] items = new T[kc.Count];
kc.CopyTo(items, 0);
return items;
}
}
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,106 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
/*============================================================
**
** Interface: ICollection
**
** <OWNER>[....]</OWNER>
**
**
** Purpose: Base interface for all generic collections.
**
**
===========================================================*/
namespace System.Collections.Generic {
using System;
using System.Runtime.CompilerServices;
using System.Diagnostics.Contracts;
// Base interface for all collections, defining enumerators, size, and
// synchronization methods.
// Note that T[] : IList<T>, and we want to ensure that if you use
// IList<YourValueType>, we ensure a YourValueType[] can be used
// without jitting. Hence the TypeDependencyAttribute on SZArrayHelper.
// This is a special hack internally though - see VM\compile.cpp.
// The same attribute is on IEnumerable<T> and ICollection<T>.
#if CONTRACTS_FULL
[ContractClass(typeof(ICollectionContract<>))]
#endif
[TypeDependencyAttribute("System.SZArrayHelper")]
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);
}
#if CONTRACTS_FULL
[ContractClassFor(typeof(ICollection<>))]
internal abstract class ICollectionContract<T> : ICollection<T>
{
int ICollection<T>.Count {
get {
Contract.Ensures(Contract.Result<int>() >= 0);
return default(int);
}
}
bool ICollection<T>.IsReadOnly {
get { return default(bool); }
}
void ICollection<T>.Add(T item)
{
//Contract.Ensures(((ICollection<T>)this).Count == Contract.OldValue(((ICollection<T>)this).Count) + 1); // not threadsafe
}
void ICollection<T>.Clear()
{
}
bool ICollection<T>.Contains(T item)
{
return default(bool);
}
void ICollection<T>.CopyTo(T[] array, int arrayIndex)
{
}
bool ICollection<T>.Remove(T item)
{
return default(bool);
}
IEnumerator<T> IEnumerable<T>.GetEnumerator()
{
return default(IEnumerator<T>);
}
IEnumerator IEnumerable.GetEnumerator()
{
return default(IEnumerator);
}
}
#endif // CONTRACTS_FULL
}

View File

@@ -0,0 +1,31 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
/*============================================================
**
** Interface: IComparer
**
** <OWNER>[....]</OWNER>
**
**
** Purpose: Interface for comparing two generic Objects.
**
**
===========================================================*/
namespace System.Collections.Generic {
using System;
// 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);
}
}

View File

@@ -0,0 +1,163 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
/*============================================================
**
** Interface: IDictionary
**
** <OWNER>[....]</OWNER>
**
**
** Purpose: Base interface for all generic dictionaries.
**
**
===========================================================*/
namespace System.Collections.Generic {
using System;
using System.Diagnostics.Contracts;
// 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.
#if CONTRACTS_FULL
[ContractClass(typeof(IDictionaryContract<,>))]
#endif // CONTRACTS_FULL
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);
}
#if CONTRACTS_FULL
[ContractClassFor(typeof(IDictionary<,>))]
internal abstract class IDictionaryContract<TKey, TValue> : IDictionary<TKey, TValue>
{
TValue IDictionary<TKey, TValue>.this[TKey key] {
get { return default(TValue); }
set { }
}
ICollection<TKey> IDictionary<TKey, TValue>.Keys {
get {
Contract.Ensures(Contract.Result<ICollection<TKey>>() != null);
return default(ICollection<TKey>);
}
}
// Returns a collections of the values in this dictionary.
ICollection<TValue> IDictionary<TKey, TValue>.Values {
get {
Contract.Ensures(Contract.Result<ICollection<TValue>>() != null);
return default(ICollection<TValue>);
}
}
bool IDictionary<TKey, TValue>.ContainsKey(TKey key)
{
return default(bool);
}
void IDictionary<TKey, TValue>.Add(TKey key, TValue value)
{
}
bool IDictionary<TKey, TValue>.Remove(TKey key)
{
//Contract.Ensures(Contract.Result<bool>() == false || ((ICollection<KeyValuePair<TKey,TValue>>)this).Count == Contract.OldValue(((ICollection<KeyValuePair<TKey,TValue>>)this).Count) - 1); // not threadsafe
return default(bool);
}
bool IDictionary<TKey, TValue>.TryGetValue(TKey key, out TValue value)
{
value = default(TValue);
return default(bool);
}
#region ICollection<KeyValuePair<TKey, TValue>> Members
void ICollection<KeyValuePair<TKey, TValue>>.Add(KeyValuePair<TKey, TValue> value)
{
//Contract.Ensures(((ICollection<KeyValuePair<TKey, TValue>>)this).Count == Contract.OldValue(((ICollection<KeyValuePair<TKey, TValue>>)this).Count) + 1); // not threadsafe
}
bool ICollection<KeyValuePair<TKey, TValue>>.IsReadOnly
{
get { return default(bool); }
}
int ICollection<KeyValuePair<TKey, TValue>>.Count
{
get {
return default(int);
}
}
void ICollection<KeyValuePair<TKey, TValue>>.Clear()
{
}
bool ICollection<KeyValuePair<TKey, TValue>>.Contains(KeyValuePair<TKey, TValue> value)
{
// Contract.Ensures(((ICollection<KeyValuePair<TKey, TValue>>)this).Count > 0 || Contract.Result<bool>() == false); // not threadsafe
return default(bool);
}
void ICollection<KeyValuePair<TKey, TValue>>.CopyTo(KeyValuePair<TKey, TValue>[] array, int startIndex)
{
//Contract.Requires(array != null);
//Contract.Requires(startIndex >= 0);
//Contract.Requires(startIndex + ((ICollection<KeyValuePair<TKey, TValue>>)this).Count <= array.Length);
}
bool ICollection<KeyValuePair<TKey, TValue>>.Remove(KeyValuePair<TKey, TValue> value)
{
// No information if removal fails.
return default(bool);
}
IEnumerator<KeyValuePair<TKey, TValue>> IEnumerable<KeyValuePair<TKey, TValue>>.GetEnumerator()
{
return default(IEnumerator<KeyValuePair<TKey, TValue>>);
}
IEnumerator IEnumerable.GetEnumerator()
{
return default(IEnumerator);
}
#endregion
}
#endif // CONTRACTS_FULL
}

View File

@@ -0,0 +1,60 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
/*============================================================
**
** Interface: IEnumerable
**
** <OWNER>[....]</OWNER>
**
**
** Purpose: Interface for providing generic IEnumerators
**
**
===========================================================*/
namespace System.Collections.Generic {
using System;
using System.Collections;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
using System.Diagnostics.Contracts;
// Implement this interface if you need to support foreach semantics.
// Note that T[] : IList<T>, and we want to ensure that if you use
// IList<YourValueType>, we ensure a YourValueType[] can be used
// without jitting. Hence the TypeDependencyAttribute on SZArrayHelper.
// This is a special hack internally though - see VM\compile.cpp.
// The same attribute is on IList<T> and ICollection<T>.
[TypeDependencyAttribute("System.SZArrayHelper")]
#if CONTRACTS_FULL
[ContractClass(typeof(IEnumerableContract<>))]
#endif // CONTRACTS_FULL
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();
}
#if CONTRACTS_FULL
[ContractClassFor(typeof(IEnumerable<>))]
internal abstract class IEnumerableContract<T> : IEnumerable<T>
{
[Pure]
IEnumerator<T> IEnumerable<T>.GetEnumerator()
{
Contract.Ensures(Contract.Result<IEnumerator<T>>() != null);
return default(IEnumerator<T>);
}
IEnumerator IEnumerable.GetEnumerator()
{
return default(IEnumerator);
}
}
#endif // CONTRACTS_FULL
}

View File

@@ -0,0 +1,36 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
/*============================================================
**
** Interface: IEnumerator
**
** <OWNER>[....]</OWNER>
**
**
** Purpose: Base interface for all generic enumerators.
**
**
===========================================================*/
namespace System.Collections.Generic {
using System;
using System.Runtime.InteropServices;
// 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;
}
}
}

View File

@@ -0,0 +1,21 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
// <OWNER>[....]</OWNER>
//
namespace System.Collections.Generic {
using System;
// 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);
}
}

View File

@@ -0,0 +1,152 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
/*============================================================
**
** Interface: IList
**
** <OWNER>[....]</OWNER>
**
**
** Purpose: Base interface for all generic lists.
**
**
===========================================================*/
namespace System.Collections.Generic {
using System;
using System.Collections;
using System.Runtime.CompilerServices;
using System.Diagnostics.Contracts;
// 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.
// Note that T[] : IList<T>, and we want to ensure that if you use
// IList<YourValueType>, we ensure a YourValueType[] can be used
// without jitting. Hence the TypeDependencyAttribute on SZArrayHelper.
// This is a special hack internally though - see VM\compile.cpp.
// The same attribute is on IEnumerable<T> and ICollection<T>.
[TypeDependencyAttribute("System.SZArrayHelper")]
#if CONTRACTS_FULL
[ContractClass(typeof(IListContract<>))]
#endif // CONTRACTS_FULL
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);
}
#if CONTRACTS_FULL
[ContractClassFor(typeof(IList<>))]
internal abstract class IListContract<T> : IList<T>
{
T IList<T>.this[int index] {
get {
//Contract.Requires(index >= 0);
//Contract.Requires(index < ((ICollection<T>)this).Count);
return default(T);
}
set {
//Contract.Requires(index >= 0);
//Contract.Requires(index < ((ICollection<T>)this).Count);
}
}
IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
return default(IEnumerator);
}
IEnumerator<T> IEnumerable<T>.GetEnumerator()
{
return default(IEnumerator<T>);
}
[Pure]
int IList<T>.IndexOf(T value)
{
Contract.Ensures(Contract.Result<int>() >= -1);
Contract.Ensures(Contract.Result<int>() < ((ICollection<T>)this).Count);
return default(int);
}
void IList<T>.Insert(int index, T value)
{
//Contract.Requires(index >= 0);
//Contract.Requires(index <= ((ICollection<T>)this).Count); // For inserting immediately after the end.
//Contract.Ensures(((ICollection<T>)this).Count == Contract.OldValue(((ICollection<T>)this).Count) + 1); // Not threadsafe
}
void IList<T>.RemoveAt(int index)
{
//Contract.Requires(index >= 0);
//Contract.Requires(index < ((ICollection<T>)this).Count);
//Contract.Ensures(((ICollection<T>)this).Count == Contract.OldValue(((ICollection<T>)this).Count) - 1); // Not threadsafe
}
#region ICollection<T> Members
void ICollection<T>.Add(T value)
{
//Contract.Ensures(((ICollection<T>)this).Count == Contract.OldValue(((ICollection<T>)this).Count) + 1); // Not threadsafe
}
bool ICollection<T>.IsReadOnly {
get { return default(bool); }
}
int ICollection<T>.Count {
get {
return default(int);
}
}
void ICollection<T>.Clear()
{
// For fixed-sized collections like arrays, Clear will not change the Count property.
// But we can't express that in a contract because we have no IsFixedSize property on
// our generic collection interfaces.
}
bool ICollection<T>.Contains(T value)
{
return default(bool);
}
void ICollection<T>.CopyTo(T[] array, int startIndex)
{
//Contract.Requires(array != null);
//Contract.Requires(startIndex >= 0);
//Contract.Requires(startIndex + ((ICollection<T>)this).Count <= array.Length);
}
bool ICollection<T>.Remove(T value)
{
// No information if removal fails.
return default(bool);
}
#endregion
}
#endif // CONTRACTS_FULL
}

View File

@@ -0,0 +1,61 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
/*============================================================
**
** Interface: IReadOnlyCollection<T>
**
** <OWNER>[....]</OWNER>
**
** Purpose: Base interface for read-only generic lists.
**
===========================================================*/
using System;
using System.Diagnostics.Contracts;
using System.Runtime.CompilerServices;
namespace System.Collections.Generic
{
// Provides a read-only, covariant view of a generic list.
// Note that T[] : IReadOnlyList<T>, and we want to ensure that if you use
// IList<YourValueType>, we ensure a YourValueType[] can be used
// without jitting. Hence the TypeDependencyAttribute on SZArrayHelper.
// This is a special hack internally though - see VM\compile.cpp.
// The same attribute is on IList<T>, IEnumerable<T>, ICollection<T>, and IReadOnlyList<T>.
[TypeDependencyAttribute("System.SZArrayHelper")]
#if CONTRACTS_FULL
[ContractClass(typeof(IReadOnlyCollectionContract<>))]
#endif
// If we ever implement more interfaces on IReadOnlyCollection, we should also update RuntimeTypeCache.PopulateInterfaces() in rttype.cs
public interface IReadOnlyCollection<out T> : IEnumerable<T>
{
int Count { get; }
}
#if CONTRACTS_FULL
[ContractClassFor(typeof(IReadOnlyCollection<>))]
internal abstract class IReadOnlyCollectionContract<T> : IReadOnlyCollection<T>
{
int IReadOnlyCollection<T>.Count {
get {
Contract.Ensures(Contract.Result<int>() >= 0);
return default(int);
}
}
IEnumerator<T> IEnumerable<T>.GetEnumerator()
{
return default(IEnumerator<T>);
}
IEnumerator IEnumerable.GetEnumerator()
{
return default(IEnumerator);
}
}
#endif
}

View File

@@ -0,0 +1,85 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
/*============================================================
**
** Interface: IReadOnlyDictionary<TKey, TValue>
**
** <OWNER>[....]</OWNER>
**
** Purpose: Base interface for read-only generic dictionaries.
**
===========================================================*/
using System;
using System.Diagnostics.Contracts;
namespace System.Collections.Generic
{
// Provides a read-only view of a generic dictionary.
#if CONTRACTS_FULL
[ContractClass(typeof(IReadOnlyDictionaryContract<,>))]
#endif
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; }
}
#if CONTRACTS_FULL
[ContractClassFor(typeof(IReadOnlyDictionary<,>))]
internal abstract class IReadOnlyDictionaryContract<TKey, TValue> : IReadOnlyDictionary<TKey, TValue>
{
bool IReadOnlyDictionary<TKey, TValue>.ContainsKey(TKey key)
{
return default(bool);
}
bool IReadOnlyDictionary<TKey, TValue>.TryGetValue(TKey key, out TValue value)
{
value = default(TValue);
return default(bool);
}
TValue IReadOnlyDictionary<TKey, TValue>.this[TKey key]
{
get { return default(TValue); }
}
IEnumerable<TKey> IReadOnlyDictionary<TKey, TValue>.Keys {
get {
Contract.Ensures(Contract.Result<IEnumerable<TKey>>() != null);
return default(IEnumerable<TKey>);
}
}
IEnumerable<TValue> IReadOnlyDictionary<TKey, TValue>.Values {
get {
Contract.Ensures(Contract.Result<IEnumerable<TValue>>() != null);
return default(IEnumerable<TValue>);
}
}
IEnumerator<KeyValuePair<TKey, TValue>> IEnumerable<KeyValuePair<TKey, TValue>>.GetEnumerator()
{
return default(IEnumerator<KeyValuePair<TKey, TValue>>);
}
int IReadOnlyCollection<KeyValuePair<TKey, TValue>>.Count {
get {
return default(int);
}
}
IEnumerator IEnumerable.GetEnumerator()
{
return default(IEnumerator);
}
}
#endif
}

View File

@@ -0,0 +1,68 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
/*============================================================
**
** Interface: IReadOnlyList<T>
**
** <OWNER>[....]</OWNER>
**
** Purpose: Base interface for read-only generic lists.
**
===========================================================*/
using System;
using System.Diagnostics.Contracts;
using System.Runtime.CompilerServices;
namespace System.Collections.Generic
{
// Provides a read-only, covariant view of a generic list.
// Note that T[] : IReadOnlyList<T>, and we want to ensure that if you use
// IList<YourValueType>, we ensure a YourValueType[] can be used
// without jitting. Hence the TypeDependencyAttribute on SZArrayHelper.
// This is a special hack internally though - see VM\compile.cpp.
// The same attribute is on IList<T>, IEnumerable<T>, ICollection<T> and IReadOnlyCollection<T>.
[TypeDependencyAttribute("System.SZArrayHelper")]
#if CONTRACTS_FULL
[ContractClass(typeof(IReadOnlyListContract<>))]
#endif
// If we ever implement more interfaces on IReadOnlyList, we should also update RuntimeTypeCache.PopulateInterfaces() in rttype.cs
public interface IReadOnlyList<out T> : IReadOnlyCollection<T>
{
T this[int index] { get; }
}
#if CONTRACTS_FULL
[ContractClassFor(typeof(IReadOnlyList<>))]
internal abstract class IReadOnlyListContract<T> : IReadOnlyList<T>
{
T IReadOnlyList<T>.this[int index] {
get {
//Contract.Requires(index >= 0);
//Contract.Requires(index < ((ICollection<T>)this).Count);
return default(T);
}
}
int IReadOnlyCollection<T>.Count {
get {
return default(int);
}
}
IEnumerator<T> IEnumerable<T>.GetEnumerator()
{
return default(IEnumerator<T>);
}
IEnumerator IEnumerable.GetEnumerator()
{
return default(IEnumerator);
}
}
#endif
}

View File

@@ -0,0 +1,47 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
/*=============================================================================
**
** Class: KeyNotFoundException
**
** <OWNER>[....]</OWNER>
**
**
** Purpose: Exception class for Hashtable and Dictionary.
**
**
=============================================================================*/
namespace System.Collections.Generic {
using System;
using System.Runtime.Remoting;
using System.Runtime.Serialization;
[Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public class KeyNotFoundException : SystemException, ISerializable {
public KeyNotFoundException ()
: base(Environment.GetResourceString("Arg_KeyNotFound")) {
SetErrorCode(System.__HResults.COR_E_KEYNOTFOUND);
}
public KeyNotFoundException(String message)
: base(message) {
SetErrorCode(System.__HResults.COR_E_KEYNOTFOUND);
}
public KeyNotFoundException(String message, Exception innerException)
: base(message, innerException) {
SetErrorCode(System.__HResults.COR_E_KEYNOTFOUND);
}
protected KeyNotFoundException(SerializationInfo info, StreamingContext context) : base(info, context) {
}
}
}

View File

@@ -0,0 +1,57 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
/*============================================================
**
** Interface: KeyValuePair
**
** <OWNER>[....]</OWNER>
**
**
** Purpose: Generic key-value pair for dictionary enumerators.
**
**
===========================================================*/
namespace System.Collections.Generic {
using System;
using System.Text;
// 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;
private TValue value;
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() {
StringBuilder s = StringBuilderCache.Acquire();
s.Append('[');
if( Key != null) {
s.Append(Key.ToString());
}
s.Append(", ");
if( Value != null) {
s.Append(Value.ToString());
}
s.Append(']');
return StringBuilderCache.GetStringAndRelease(s);
}
}
}

File diff suppressed because it is too large Load Diff