| 1 |
// ==++== |
| 2 |
// |
| 3 |
// Copyright (c) Microsoft Corporation. All rights reserved. |
| 4 |
// |
| 5 |
// ==--== |
| 6 |
/*============================================================ |
| 7 |
** |
| 8 |
** Interface: IReadOnlyCollection<T> |
| 9 |
** |
| 10 |
** <OWNER>matell</OWNER> |
| 11 |
** |
| 12 |
** Purpose: Base interface for read-only generic lists. |
| 13 |
** |
| 14 |
===========================================================*/ |
| 15 |
using System; |
| 16 |
using System.Diagnostics.Contracts; |
| 17 |
using System.Runtime.CompilerServices; |
| 18 |
|
| 19 |
namespace System.Collections.Generic |
| 20 |
{ |
| 21 |
|
| 22 |
// Provides a read-only, covariant view of a generic list. |
| 23 |
|
| 24 |
// Note that T[] : IReadOnlyList<T>, and we want to ensure that if you use |
| 25 |
// IList<YourValueType>, we ensure a YourValueType[] can be used |
| 26 |
// without jitting. Hence the TypeDependencyAttribute on SZArrayHelper. |
| 27 |
// This is a special hack internally though - see VM\compile.cpp. |
| 28 |
// The same attribute is on IList<T>, IEnumerable<T>, ICollection<T>, and IReadOnlyList<T>. |
| 29 |
[TypeDependencyAttribute("System.SZArrayHelper")] |
| 30 |
#if CONTRACTS_FULL |
| 31 |
[ContractClass(typeof(IReadOnlyCollectionContract<>))] |
| 32 |
#endif |
| 33 |
// If we ever implement more interfaces on IReadOnlyCollection, we should also update RuntimeTypeCache.PopulateInterfaces() in rttype.cs |
| 34 |
public interface IReadOnlyCollection<out T> : IEnumerable<T> |
| 35 |
{ |
| 36 |
int Count { get; } |
| 37 |
} |
| 38 |
|
| 39 |
#if CONTRACTS_FULL |
| 40 |
[ContractClassFor(typeof(IReadOnlyCollection<>))] |
| 41 |
internal abstract class IReadOnlyCollectionContract<T> : IReadOnlyCollection<T> |
| 42 |
{ |
| 43 |
int IReadOnlyCollection<T>.Count { |
| 44 |
get { |
| 45 |
Contract.Ensures(Contract.Result<int>() >= 0); |
| 46 |
return default(int); |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
IEnumerator<T> IEnumerable<T>.GetEnumerator() |
| 51 |
{ |
| 52 |
return default(IEnumerator<T>); |
| 53 |
} |
| 54 |
|
| 55 |
IEnumerator IEnumerable.GetEnumerator() |
| 56 |
{ |
| 57 |
return default(IEnumerator); |
| 58 |
} |
| 59 |
} |
| 60 |
#endif |
| 61 |
} |