public void Test_GetObject_NonNull(string json)
        {
            IObjectReader reader = GetReader(json);
            IObjectReader child  = reader.GetObject("a");

            Assert.That(child, Is.Not.Null);
            Assert.That(child, Is.TypeOf <JilDynamicObjectReader>( ));
            Assert.That(child.GetInt("b"), Is.EqualTo(1));
        }
Пример #2
0
 /// <summary>
 /// Read a child object.
 /// Call when expecting one object, or a null.
 /// </summary>
 public IObjectReader GetObject(string key)
 {
     try
     {
         return(_inner.GetObject(key));
     }
     catch
     {
         return(null);
     }
 }
Пример #3
0
        public static Person DeserializePerson2(IObjectReader reader)
        {
            var obj = reader.GetObject();
            if (obj == null)
            {
                return null;
            }

            Person person = new Person();

            foreach (var member in obj.Members)
            {
                if (member.MemberKey == 1)
                {
                    person.Id = member.ReadValueAsInt32();
                }
                else if (member.MemberKey == 2)
                {
                    person.Name = member.ReadValueAsString(250);
                }
                else if (member.MemberKey == 3)
                {
                    person.Scores = member.ReadValueAsInt32Array();
                }
            }

            return person;
        }
        public void Test_GetObject_SameInstance(string json)
        {
            IObjectReader reader = GetReader(json);

            Assert.That(reader.GetObject("a"), Is.SameAs(reader.GetObject("a")));
        }
        public void Test_GetObject_Null(string json)
        {
            IObjectReader reader = GetReader(json);

            Assert.That(reader.GetObject("a"), Is.Null);
        }