Skip to content
Browse files

Adding Dictionary.Clear()

  • Loading branch information...
1 parent 171dcbe commit 51dafa405f485a382ce1cd9f38d8d2f086e6c28f @flaub committed Mar 30, 2010
View
3 src/DotWeb.System/Array.cs
@@ -107,9 +107,8 @@ public class Array
if (index > array.Length - length)
throw new IndexOutOfRangeException("index + length > size");
- var jsArray = new JsArray(array);
for (int i = 0; i < length; i++) {
- jsArray[index + i] = 0;
+ array[index + i] = 0;
}
}
#endif
View
18 src/DotWeb.System/Collections/Generic/Dictionary.cs
@@ -214,23 +214,26 @@ public Dictionary(IDictionary<TKey, TValue> dictionary)
}
public bool Contains(KeyValuePair<TKey, TValue> item) {
- throw new NotImplementedException();
+ return ContainsKeyValuePair(item);
}
public void CopyTo(KeyValuePair<TKey, TValue>[] array, int arrayIndex) {
throw new NotImplementedException();
}
public bool Remove(KeyValuePair<TKey, TValue> item) {
- throw new NotImplementedException();
+ if (!ContainsKeyValuePair(item))
+ return false;
+
+ return Remove(item.Key);
}
public int Count {
get { return this.count; }
}
public bool IsReadOnly {
- get { throw new NotImplementedException(); }
+ get { return false; }
}
#endregion
@@ -460,6 +463,15 @@ public Dictionary(IDictionary<TKey, TValue> dictionary)
threshold = (int)(newSize * DEFAULT_LOAD_FACTOR);
}
+
+ private bool ContainsKeyValuePair(KeyValuePair<TKey, TValue> pair) {
+ TValue value;
+ if (!TryGetValue(pair.Key, out value))
+ return false;
+
+ return EqualityComparer<TValue>.Default.Equals(pair.Value, value);
+ }
+
#endregion
public class Enumerator : IEnumerator<KeyValuePair<TKey, TValue>>, IDictionaryEnumerator
View
7 src/DotWeb.System/DotWeb/JsArray.cs
@@ -35,8 +35,11 @@ namespace System.DotWeb
[JsCamelCase]
public class JsArray : JsObject
{
- [JsMacro("{0}")]
- public extern JsArray(Array array);
+ [JsMacro("{1}")]
+ public static extern implicit operator JsArray(Array array);
+
+ [JsMacro("{1}")]
+ public static extern implicit operator Array(JsArray array);
/// <summary>
/// <para>
View
5 test/DotWeb.Functional.Test/Client/DictionaryTest.cs
@@ -35,6 +35,11 @@ class DictionaryTest : JsScript
dict.Add("other", "other");
return dict;
});
+
+ this.view.AreStringsEqual("dict.Clear()", "{}", () => {
+ dict.Clear();
+ return dict;
+ });
}
}
}

0 comments on commit 51dafa4

Please sign in to comment.
Something went wrong with that request. Please try again.