public void ToJson(JsonFormatter f) { f.Key("type"); f.Value("string"); f.Key("enum"); f.BeginList(); foreach (var x in Values) { f.Value(x); } f.EndList(); }
static void SerializeList <T>(IEnumerable <T> values, string json, Action <JsonFormatter, T> seri) { var b = new BytesStore(); var f = new JsonFormatter(b); f.BeginList(); foreach (var value in values) { seri(f, value); } f.EndList(); Assert.AreEqual(json, new Utf8String(b.Bytes).ToString()); }
public void KeyValue() { var p = new Point { X = 1, Vector = new float[] { 1, 2, 3 } }; var f = new JsonFormatter(); f.BeginMap(); f.Key(nameof(p.Vector)); f.BeginList(); f.Value(p.Vector[0]); f.Value(p.Vector[1]); f.Value(p.Vector[2]); f.EndList(); f.EndMap(); var json = JsonParser.Parse(new Utf8String(f.GetStoreBytes())); Assert.AreEqual(1, json.GetObjectCount()); Assert.AreEqual(1, json["Vector"][0].GetInt32()); }
public static ActionDisposer BeginListDisposable(this JsonFormatter f) { f.BeginList(); return(new ActionDisposer(() => f.EndList())); }