Debian Codegraph @

mcs/class/referencesource/mscorlib/system/collections/generic/idictionary.cs

raw
1 // ==++==
2 //
3 // Copyright (c) Microsoft Corporation. All rights reserved.
4 //
5 // ==--==
6 /*============================================================
7 **
8 ** Interface: IDictionary
9 **
10 ** <OWNER>kimhamil</OWNER>
11 **
12 **
13 ** Purpose: Base interface for all generic dictionaries.
14 **
15 **
16 ===========================================================*/
17 namespace System.Collections.Generic {
18 using System;
19 using System.Diagnostics.Contracts;
20
21 // An IDictionary is a possibly unordered set of key-value pairs.
22 // Keys can be any non-null object. Values can be any object.
23 // You can look up a value in an IDictionary via the default indexed
24 // property, Items.
25 #if CONTRACTS_FULL
26 [ContractClass(typeof(IDictionaryContract<,>))]
27 #endif // CONTRACTS_FULL
28 public interface IDictionary<TKey, TValue> : ICollection<KeyValuePair<TKey, TValue>>
29 {
30 // Interfaces are not serializable
31 // The Item property provides methods to read and edit entries
32 // in the Dictionary.
33 TValue this[TKey key] {
34 get;
35 set;
36 }
37
38 // Returns a collections of the keys in this dictionary.
39 ICollection<TKey> Keys {
40 get;
41 }
42
43 // Returns a collections of the values in this dictionary.
44 ICollection<TValue> Values {
45 get;
46 }
47
48 // Returns whether this dictionary contains a particular key.
49 //
50 bool ContainsKey(TKey key);
51
52 // Adds a key-value pair to the dictionary.
53 //
54 void Add(TKey key, TValue value);
55
56 // Removes a particular key from the dictionary.
57 //
58 bool Remove(TKey key);
59
60 bool TryGetValue(TKey key, out TValue value);
61 }
62
63 #if CONTRACTS_FULL
64 [ContractClassFor(typeof(IDictionary<,>))]
65 internal abstract class IDictionaryContract<TKey, TValue> : IDictionary<TKey, TValue>
66 {
67 TValue IDictionary<TKey, TValue>.this[TKey key] {
68 get { return default(TValue); }
69 set { }
70 }
71
72 ICollection<TKey> IDictionary<TKey, TValue>.Keys {
73 get {
74 Contract.Ensures(Contract.Result<ICollection<TKey>>() != null);
75 return default(ICollection<TKey>);
76 }
77 }
78
79 // Returns a collections of the values in this dictionary.
80 ICollection<TValue> IDictionary<TKey, TValue>.Values {
81 get {
82 Contract.Ensures(Contract.Result<ICollection<TValue>>() != null);
83 return default(ICollection<TValue>);
84 }
85 }
86
87 bool IDictionary<TKey, TValue>.ContainsKey(TKey key)
88 {
89 return default(bool);
90 }
91
92 void IDictionary<TKey, TValue>.Add(TKey key, TValue value)
93 {
94 }
95
96 bool IDictionary<TKey, TValue>.Remove(TKey key)
97 {
98 //Contract.Ensures(Contract.Result<bool>() == false || ((ICollection<KeyValuePair<TKey,TValue>>)this).Count == Contract.OldValue(((ICollection<KeyValuePair<TKey,TValue>>)this).Count) - 1); // not threadsafe
99 return default(bool);
100 }
101
102 bool IDictionary<TKey, TValue>.TryGetValue(TKey key, out TValue value)
103 {
104 value = default(TValue);
105 return default(bool);
106 }
107
108 #region ICollection<KeyValuePair<TKey, TValue>> Members
109
110 void ICollection<KeyValuePair<TKey, TValue>>.Add(KeyValuePair<TKey, TValue> value)
111 {
112 //Contract.Ensures(((ICollection<KeyValuePair<TKey, TValue>>)this).Count == Contract.OldValue(((ICollection<KeyValuePair<TKey, TValue>>)this).Count) + 1); // not threadsafe
113 }
114
115 bool ICollection<KeyValuePair<TKey, TValue>>.IsReadOnly
116 {
117 get { return default(bool); }
118 }
119
120 int ICollection<KeyValuePair<TKey, TValue>>.Count
121 {
122 get {
123 return default(int);
124 }
125 }
126
127 void ICollection<KeyValuePair<TKey, TValue>>.Clear()
128 {
129 }
130
131 bool ICollection<KeyValuePair<TKey, TValue>>.Contains(KeyValuePair<TKey, TValue> value)
132 {
133 // Contract.Ensures(((ICollection<KeyValuePair<TKey, TValue>>)this).Count > 0 || Contract.Result<bool>() == false); // not threadsafe
134 return default(bool);
135 }
136
137 void ICollection<KeyValuePair<TKey, TValue>>.CopyTo(KeyValuePair<TKey, TValue>[] array, int startIndex)
138 {
139 //Contract.Requires(array != null);
140 //Contract.Requires(startIndex >= 0);
141 //Contract.Requires(startIndex + ((ICollection<KeyValuePair<TKey, TValue>>)this).Count <= array.Length);
142 }
143
144 bool ICollection<KeyValuePair<TKey, TValue>>.Remove(KeyValuePair<TKey, TValue> value)
145 {
146 // No information if removal fails.
147 return default(bool);
148 }
149
150 IEnumerator<KeyValuePair<TKey, TValue>> IEnumerable<KeyValuePair<TKey, TValue>>.GetEnumerator()
151 {
152 return default(IEnumerator<KeyValuePair<TKey, TValue>>);
153 }
154
155 IEnumerator IEnumerable.GetEnumerator()
156 {
157 return default(IEnumerator);
158 }
159
160 #endregion
161 }
162 #endif // CONTRACTS_FULL
163 }