95 |
{ |
{ |
96 |
Type t = typeof(Dictionary<TKey, TValue>); |
Type t = typeof(Dictionary<TKey, TValue>); |
97 |
var field = t.GetField("version", BindingFlags.NonPublic | BindingFlags.Instance); |
var field = t.GetField("version", BindingFlags.NonPublic | BindingFlags.Instance); |
98 |
var v = Convert.ToInt32(field.GetValue(properties)); |
var v = Convert.ToInt32(field.GetValue(this.properties)); |
99 |
return v; |
return v; |
100 |
} |
} |
101 |
} |
} |
161 |
list.CopyTo(array, arrayIndex); |
list.CopyTo(array, arrayIndex); |
162 |
} |
} |
163 |
public bool RemoveProperty(IPropertyValuePair<TKey, TValue> item) { return RemoveProperty(item.Name); } |
public bool RemoveProperty(IPropertyValuePair<TKey, TValue> item) { return RemoveProperty(item.Name); } |
164 |
IEnumerator<IPropertyValuePair<TKey, TValue>> IEnumerable<IPropertyValuePair<TKey, TValue>>.GetEnumerator() { return new PropertyDictionaryEnumerator(this, 2); } |
public IEnumerator<IPropertyValuePair<TKey, TValue>> GetEnumerator() |
165 |
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return properties.GetEnumerator(); } |
{ |
166 |
|
//return new PropertyDictionaryEnumerator(this, 2); |
167 |
|
List<IPropertyValuePair<TKey, TValue>> list = new List<IPropertyValuePair<TKey, TValue>>(); |
168 |
|
foreach (var k in properties) { list.Add(new PropertyValuePair<TKey, TValue>(k.Key, k.Value)); } |
169 |
|
return list.GetEnumerator(); |
170 |
|
} |
171 |
|
IEnumerator IEnumerable.GetEnumerator() { return properties.GetEnumerator(); } |
172 |
|
|
173 |
public override string ToString() |
public override string ToString() |
174 |
{ |
{ |
175 |
return string.Format("Property Count: {0}", PropertyCount); |
return string.Format("Property Count: {0}", PropertyCount); |
176 |
} |
} |
177 |
#region enumerator support |
#region enumerator support |
178 |
public class PropertyDictionaryEnumerator : IEnumerator<IPropertyValuePair<TKey, TValue>>, IDisposable |
//public class PropertyDictionaryEnumerator : IEnumerator<IPropertyValuePair<TKey, TValue>>, IDisposable |
179 |
{ |
//{ |
180 |
private PropertyDictionary<TKey, TValue> dictionary; |
// private PropertyDictionary<TKey, TValue> dictionary; |
181 |
private int index; |
// private int index; |
182 |
private IPropertyValuePair<TKey, TValue> current; |
// private IPropertyValuePair<TKey, TValue> current; |
183 |
private int getEnumeratorRetType; |
// private int getEnumeratorRetType; |
184 |
internal const int DictEntry = 1; |
// internal const int DictEntry = 1; |
185 |
internal const int KeyValuePair = 2; |
// internal const int KeyValuePair = 2; |
186 |
private int version; |
// private int version; |
187 |
public PropertyDictionaryEnumerator(PropertyDictionary<TKey, TValue> dictionary, int getEnumeratorRetType) |
// public PropertyDictionaryEnumerator(PropertyDictionary<TKey, TValue> dictionary, int getEnumeratorRetType) |
188 |
{ |
// { |
189 |
this.dictionary = dictionary; |
// this.dictionary = dictionary; |
190 |
this.version = dictionary.version; |
// //this.version = dictionary.version; |
191 |
this.index = 0; |
// this.index = 0; |
192 |
this.getEnumeratorRetType = getEnumeratorRetType; |
// this.getEnumeratorRetType = getEnumeratorRetType; |
193 |
this.current = new PropertyValuePair<TKey, TValue>(); |
// this.current = new PropertyValuePair<TKey, TValue>(); |
194 |
} |
// } |
195 |
|
// public IPropertyValuePair<TKey, TValue> Current |
196 |
public IPropertyValuePair<TKey, TValue> Current |
// { |
197 |
{ |
// get { return this.current; } |
198 |
get { return this.current; } |
// } |
199 |
} |
// public void Dispose() |
200 |
|
// { |
201 |
public void Dispose() |
// } |
202 |
{ |
// object IEnumerator.Current |
203 |
} |
// { |
204 |
|
// get |
205 |
object IEnumerator.Current |
// { |
206 |
{ |
// if ((this.index == 0) || (this.index == (this.dictionary.Count() + 1))) |
207 |
get |
// { |
208 |
{ |
// throw new InvalidOperationException("Operation can't happen"); |
209 |
if ((this.index == 0) || (this.index == (this.dictionary.Count() + 1))) |
// } |
210 |
{ |
// if (this.getEnumeratorRetType == 1) |
211 |
throw new InvalidOperationException("Operation can't happen"); |
// { |
212 |
} |
// return new DictionaryEntry(this.current.Name, this.current.Value); |
213 |
if (this.getEnumeratorRetType == 1) |
// } |
214 |
{ |
// return new PropertyValuePair<TKey, TValue>(this.current.Name, this.current.Value); |
215 |
return new DictionaryEntry(this.current.Name, this.current.Value); |
// } |
216 |
} |
// } |
217 |
return new PropertyValuePair<TKey, TValue>(this.current.Name, this.current.Value); |
// public bool MoveNext() |
218 |
} |
// { |
219 |
} |
// //if (this.version != this.dictionary.version) |
220 |
|
// //{ |
221 |
public bool MoveNext() |
// // ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumFailedVersion); |
222 |
{ |
// //} |
223 |
if (this.version != this.dictionary.version) |
// while (this.index < this.dictionary.Count()) |
224 |
{ |
// { |
225 |
ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumFailedVersion); |
// if (this.dictionary.entries[this.index].hashCode >= 0) |
226 |
} |
// { |
227 |
while (this.index < this.dictionary.Count()) |
// this.current =(IPropertyValuePair<TKey,TValue>)(PropertyValuePair<TKey,TValue>)new KeyValuePair<TKey, TValue>(this.dictionary.entries[this.index].name, this.dictionary.entries[this.index].value); |
228 |
{ |
// this.index++; |
229 |
if (this.dictionary.entries[this.index].hashCode >= 0) |
// return true; |
230 |
{ |
// } |
231 |
this.current =(IPropertyValuePair<TKey,TValue>)(PropertyValuePair<TKey,TValue>)new KeyValuePair<TKey, TValue>(this.dictionary.entries[this.index].name, this.dictionary.entries[this.index].value); |
// this.index++; |
232 |
this.index++; |
// } |
233 |
return true; |
// this.index = this.dictionary.Count() + 1; |
234 |
} |
// this.current = new PropertyValuePair<TKey, TValue>(); |
235 |
this.index++; |
// return false; |
236 |
} |
// } |
237 |
this.index = this.dictionary.Count() + 1; |
// public void Reset() |
238 |
this.current = new PropertyValuePair<TKey, TValue>(); |
// { |
239 |
return false; |
// //if (this.version != this.dictionary.version) |
240 |
} |
// //{ |
241 |
public void Reset() |
// // ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumFailedVersion); |
242 |
{ |
// //} |
243 |
if (this.version != this.dictionary.version) |
// this.index = 0; |
244 |
{ |
// this.current = (IPropertyValuePair<TKey, TValue>)(PropertyValuePair<TKey, TValue>)new KeyValuePair<TKey, TValue>(); |
245 |
ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumFailedVersion); |
// } |
246 |
} |
//} |
|
this.index = 0; |
|
|
this.current = (IPropertyValuePair<TKey, TValue>)(PropertyValuePair<TKey, TValue>)new KeyValuePair<TKey, TValue>(); |
|
|
} |
|
|
} |
|
247 |
#endregion |
#endregion |
248 |
} |
} |
249 |
|
|