public void NotifyChangedText() { var propDict = new Dictionary<string, string>(); JsonObject jso = new JsonObject(); jso.PropertyChanged += (obj, e) => { propDict.Add(e.PropertyName, ""); }; dynamic djso = jso; Assert.IsFalse(propDict.ContainsKey("Name")); djso.Name = "JP"; Assert.IsTrue(propDict.ContainsKey("Name")); propDict.Clear(); Assert.IsFalse(propDict.ContainsKey("Name")); djso["Name"] = "JP"; Assert.IsTrue(propDict.ContainsKey("Name")); propDict.Clear(); djso.RemoveAll(); Assert.IsFalse(propDict.ContainsKey("Name")); djso.Add("Name", "JP"); Assert.IsTrue(propDict.ContainsKey("Name")); propDict.Clear(); }
public void SetTest() { dynamic jso = new JsonObject(); Assert.AreEqual(0, jso.Keys.Count); jso.IsManager = true; Assert.AreEqual(1, jso.Keys.Count); Assert.AreEqual(true, jso.IsManager); jso["Something"] = 1.0; Assert.AreEqual(1.0, jso.Something); }
public void AddTest() { dynamic jso = new JsonObject(); Assert.AreEqual(0, jso.Keys.Count); jso.Add("Name", "JP"); Assert.AreEqual("JP", jso["Name"]); Assert.AreEqual("JP", jso.Name); Assert.AreEqual(1, jso.Keys.Count); jso.Add("Not-Valid", "Yup"); Assert.AreEqual("Yup", jso["Not-Valid"]); Assert.AreEqual(2, jso.Keys.Count); }
protected dynamic ParseObject() { Read(); //read first { ReadWhitespace(); dynamic obj = new JsonObject(); var doRead = true; while (doRead) { switch (Peek()) { case -1: ParseError("Unterminated object before end of json string."); return obj; case ',': Read(); break; case '}': Read(); doRead = false; break; case '"': var key = ParseString(); if (CamelizeProperties) { _sb.Clear(); if (key.Contains('_')) { var words = key.Split('_'); foreach (var w in words) { _sb.Append(w.Substring(0, 1).ToUpper()); _sb.Append(w.Substring(1, w.Length - 1).ToLower()); } } else { _sb.Append(key.Substring(0, 1).ToUpper()); _sb.Append(key.Substring(1, key.Length - 1).ToLower()); } key = _sb.ToString(); } ReadWhitespace(); ReadExpect(':'); ReadWhitespace(); var val = ParseValue(); obj[key] = val; break; default: ReadWhitespace(); break; } } return obj; }