예제 #1
0
        IJSonMutableObject IJSonMutableObject.SetArray(string name)
        {
            IJSonMutableObject array = JSonMutableObject.CreateArray();

            SetValue(name, array);
            return(array);
        }
예제 #2
0
        IJSonMutableObject IJSonMutableObject.SetDictionary(string name)
        {
            IJSonMutableObject dict = JSonMutableObject.CreateDictionary();

            SetValue(name, dict);
            return(dict);
        }
예제 #3
0
        IJSonMutableObject IJSonMutableObject.InsertDictionaryAt(int index)
        {
            IJSonMutableObject dict = JSonMutableObject.CreateDictionary();

            InsertValue(index, dict);
            return(dict);
        }
예제 #4
0
        IJSonMutableObject IJSonMutableObject.InsertArrayAt(int index)
        {
            IJSonMutableObject array = JSonMutableObject.CreateArray();

            InsertValue(index, array);
            return(array);
        }
예제 #5
0
        public void CreateMutableObjectFromScratch()
        {
            var jo   = JSonMutableObject.CreateDictionary();
            var now  = DateTime.Now;
            var guid = Guid.NewGuid();

            jo.SetValue("name", "Paweł");
            jo.SetValue("age", 12);
            jo.SetValue("date", now, JSonDateTimeKind.Ticks);
            jo.SetValue("id", guid);
            jo.SetNull("school");

            var sa = jo.SetArray("items");

            sa.SetValue(1);
            sa.SetValue(2);
            sa.SetValue(3);

            var so = jo.SetDictionary("location");

            so.SetValue("latitude", 1.23d);
            so.SetValue("longigute", 1.24d);
            so.SetValue("city", "WRO");
            so.SetValue("country", "PL");

            var dates = JSonMutableObject.CreateArray();

            dates.SetValue(now.AddDays(1));
            dates.SetValue(now.AddMinutes(100));
            dates.SetValue(now.AddYears(2));

            jo.SetValue("dates", dates);

            writer.Write(jo);
            Assert.IsNotNull(writer.ToString(), "Should serialize as some kind of data!");

            var ic = jo.CreateImmutableClone(); // create immutable clone, where the values will be checked!

            Assert.IsTrue(ic.Contains("school"), "Should contain the 'school' item!");
            Assert.IsNull(ic["school"].StringValue, "'school' item should be equal to null!");
            Assert.AreEqual(now, ic["date"].ToDateTimeValue(JSonDateTimeKind.Ticks), "Incompatible current date!");
            Assert.AreEqual(3, ic["items"].Count, "There should be sub-array with 3 items!");
            Assert.AreEqual(2, ic["items"][1].Int32Value, "Invalid sub-array item value!");
            Assert.AreEqual(1.23d, ic["location"]["latitude"].DoubleValue, "Invalid latitude!");
        }
예제 #6
0
        public void WriteAnObjectWithSomeItems()
        {
            var o = JSonMutableObject.CreateDictionary();

            o.SetValue("Name", "Paweł");
            o.SetValue("age", 12);
            var currencies = o.SetArray("currencies");

            currencies.SetValue("PLN");
            currencies.SetValue("EUR");
            currencies.SetValue("USD");
            currencies.SetValue("XKG");

            writer.Write(o);

            Console.WriteLine(writer);
            Assert.AreNotEqual("{}", writer.ToString(), "Not expected an empty object here!");
        }
        /// <summary>
        /// Creates new IJSonMutableObject containing all basic fields for typical bayeux response message.
        /// </summary>
        public IJSonMutableObject CreateEmptyBayeuxResponse(int internalStatus, string channel)
        {
            if (string.IsNullOrEmpty(channel))
            {
                throw new ArgumentNullException("channel");
            }

            var message = JSonMutableObject.CreateDictionary();

            message.SetDictionary("data");

            var ext = message.SetDictionary("ext");

            if (internalStatus >= 0)
            {
                ext.SetValue("status", internalStatus);
            }

            message.SetValue("channel", channel);
            return(message);
        }
예제 #8
0
 IJSonMutableObject IJSonObject.CreateMutableClone()
 {
     return(JSonMutableObject.CreateArray(this));
 }
예제 #9
0
 IJSonMutableObject IJSonObject.CreateMutableClone()
 {
     return(JSonMutableObject.CreateDictionary(this));
 }