2008-09-15 Atsushi Enomoto <atsushi@ximian.com>
authorAtsushi Eno <atsushieno@gmail.com>
Mon, 15 Sep 2008 03:51:41 +0000 (03:51 -0000)
committerAtsushi Eno <atsushieno@gmail.com>
Mon, 15 Sep 2008 03:51:41 +0000 (03:51 -0000)
* JsonObject.cs, JsonValue.cs : SL2b2 updates.

svn path=/trunk/mcs/; revision=112982

mcs/class/System.Json/System.Json/ChangeLog
mcs/class/System.Json/System.Json/JsonObject.cs
mcs/class/System.Json/System.Json/JsonValue.cs

index 1747612bb4668d7751d74b1bd2e325a6ff414197..fa14f6ac6c32949a58059a56aead9b4f0873a573 100644 (file)
@@ -1,3 +1,7 @@
+2008-09-15  Atsushi Enomoto  <atsushi@ximian.com>
+
+       * JsonObject.cs, JsonValue.cs : SL2b2 updates.
+
 2008-08-28  Atsushi Enomoto  <atsushi@ximian.com>
 
        * JsonReader.cs : a ReadChar() is missing in number parsing.
index 3d5d522f5ac62054ac76dddcf05815281a632231..128c7fba6c1de71e835d4aec441cfb5e9ef22159 100644 (file)
@@ -11,7 +11,7 @@ using JsonPairEnumerable = System.Collections.Generic.IEnumerable<System.Collect
 
 namespace System.Json
 {
-       public class JsonObject : JsonValue//, IDictionary<string, JsonValue>, ICollection<KeyValuePair<string, JsonValue>>
+       public class JsonObject : JsonValue, IDictionary<string, JsonValue>, ICollection<KeyValuePair<string, JsonValue>>
        {
                int known_count = -1;
                Dictionary<string, JsonValue> map;
@@ -58,6 +58,10 @@ namespace System.Json
                        get { return false; }
                }
 
+               bool ICollection<JsonPair>.IsReadOnly {
+                       get { return ((ICollection<JsonPair>) map).IsReadOnly; }
+               }
+
                public override sealed JsonValue this [string key] {
                        get {
                                foreach (JsonPair pair in AsEnumerable ())
@@ -75,17 +79,17 @@ namespace System.Json
                        get { return JsonType.Object; }
                }
 
-               public IEnumerable<string> Keys {
+               public ICollection<string> Keys {
                        get {
-                               foreach (JsonPair pair in AsEnumerable ())
-                                       yield return pair.Key;
+                               PopulateMap ();
+                               return map.Keys;
                        }
                }
 
-               public IEnumerable<JsonValue> Values {
+               public ICollection<JsonValue> Values {
                        get {
-                               foreach (JsonPair pair in AsEnumerable ())
-                                       yield return pair.Value;
+                               PopulateMap ();
+                               return map.Values;
                        }
                }
 
@@ -127,12 +131,17 @@ namespace System.Json
                                source = empty;
                }
 
+               bool ICollection<JsonPair>.Contains (JsonPair item)
+               {
+                       return ContainsKey (item.Key);
+               }
+
                public override bool ContainsKey (string key)
                {
                        if (key == null)
                                throw new ArgumentNullException ("key");
-                       foreach (string k in Keys)
-                               if (k == key)
+                       foreach (JsonPair p in AsEnumerable ())
+                               if (p.Key == key)
                                        return true;
                        return false;
                }
@@ -143,10 +152,15 @@ namespace System.Json
                                array [arrayIndex++] = p;
                }
 
-               public void Remove (string key)
+               public bool Remove (string key)
                {
                        PopulateMap ();
-                       map.Remove (key);
+                       return map.Remove (key);
+               }
+
+               bool ICollection<JsonPair>.Remove (JsonPair item)
+               {
+                       return ((ICollection<JsonPair>) map).Remove (item);
                }
 
                public override void Save (Stream stream)
@@ -166,6 +180,17 @@ namespace System.Json
                        stream.WriteByte ((byte) '}');
                }
 
+               public bool TryGetValue (string key, out JsonValue value)
+               {
+                       foreach (JsonPair p in AsEnumerable ())
+                               if (p.Key == key) {
+                                       value = p.Value;
+                                       return true;
+                               }
+                       value = null;
+                       return false;
+               }
+
                void PopulateMap ()
                {
                        if (map == null) {
index bfbcc91ee3b7306aff5f2d14482e9cc6d69e8da7..cfabaf28f9454e355f847c7e5f1e05b919037090 100644 (file)
@@ -9,7 +9,7 @@ using JsonPair = System.Collections.Generic.KeyValuePair<string, System.Json.Jso
 
 namespace System.Json
 {
-       public abstract class JsonValue
+       public abstract class JsonValue : IEnumerable
        {
                public static JsonValue Load (Stream stream)
                {
@@ -111,6 +111,11 @@ namespace System.Json
                        return sw.ToString ();
                }
 
+               IEnumerator IEnumerable.GetEnumerator ()
+               {
+                       throw new InvalidOperationException ();
+               }
+
                internal string EscapeString (string src)
                {
                        for (int i = 0; i < src.Length; i++)