示例#1
0
        public void TestReadUnknown()
        {
            Assert.AreEqual(TransitFactory.TaggedValue("j", "foo"), Reader("\"~jfoo\"").Read <ITaggedValue>());
            IList <object> l = new List <object> {
                1L, 2L
            };

            ITaggedValue expected = TransitFactory.TaggedValue("point", l);
            ITaggedValue result   = Reader("{\"~#point\":[1,2]}").Read <ITaggedValue>();

            Assert.AreEqual(expected.Tag, result.Tag);
            CollectionAssert.AreEqual(((IList <object>)expected.Representation).ToArray(), ((IList <object>)result.Representation).ToArray());
        }
示例#2
0
        public void TestWriteUnknown()
        {
            var l = new List <object>();

            l.Add("`jfoo");
            Assert.AreEqual("[\"~`jfoo\"]", WriteJsonVerbose(l));
            Assert.AreEqual(ScalarVerbose("\"~`jfoo\""), WriteJsonVerbose("`jfoo"));

            var l2 = new List <object>();

            l2.Add(1L);
            l2.Add(2L);
            Assert.AreEqual("{\"~#point\":[1,2]}", WriteJsonVerbose(TransitFactory.TaggedValue("point", l2)));
        }
示例#3
0
        public override object Representation(object obj)
        {
            dynamic o = obj;

            if (StringableKeys(o))
            {
                return(Enumerable.ToList(o));
            }
            else
            {
                var l = new List <object>();

                foreach (var item in o)
                {
                    l.Add(item.Key);
                    l.Add(item.Value);
                }

                return(TransitFactory.TaggedValue("array", l));
            }
        }
示例#4
0
 public override object Representation(object obj)
 {
     return(TransitFactory.TaggedValue("array", obj));
 }
示例#5
0
 public ITaggedValue FromRepresentation(string tag, object representation)
 {
     return(TransitFactory.TaggedValue(tag, representation));
 }