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()); }
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))); }
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)); } }
public override object Representation(object obj) { return(TransitFactory.TaggedValue("array", obj)); }
public ITaggedValue FromRepresentation(string tag, object representation) { return(TransitFactory.TaggedValue(tag, representation)); }