예제 #1
0
 public void ToJson(JsonFormatter f)
 {
     f.BeginMap();
     if (!string.IsNullOrEmpty(Title))
     {
         f.Key("title"); f.Value(Title);
     }
     if (!string.IsNullOrEmpty(Description))
     {
         f.Key("description"); f.Value(Description);
     }
     Validator.ToJson(f);
     f.EndMap();
 }
 public void ToJson(JsonFormatter f)
 {
     f.Key("type"); f.Value("object");
     if (Properties.Count > 0)
     {
         f.Key("properties");
         f.BeginMap();
         foreach (var kv in Properties)
         {
             f.Key(kv.Key);
             kv.Value.ToJson(f);
         }
         f.EndMap();
     }
 }
        public void KeyValue()
        {
            var p = new Point
            {
                X      = 1,
                Vector = new float[] { 1, 2, 3 }
            };

            var f = new JsonFormatter();

            f.BeginMap();
            f.KeyValue(() => p.Vector);
            f.EndMap();

            var json = JsonParser.Parse(new Utf8String(f.GetStoreBytes()));

            Assert.AreEqual(1, json.GetObjectCount());
            Assert.AreEqual(1, json["Vector"][0].GetInt32());
        }
        public void Serialize(JsonFormatter f, JsonSchemaValidationContext c, Object o)
        {
            // validate properties
            m_validValueMap.Clear();

            using (f.BeginMap())
            {
                var dict = o as Dictionary <string, T>;
                foreach (var kv in dict)
                {
                    // key
                    f.Key(kv.Key);

                    // value
                    using (c.Push(kv.Key))
                    {
                        AdditionalProperties.Validator.Serialize(f, c, kv.Value);
                    }
                }
            }
        }
 public static ActionDisposer BeginMapDisposable(this JsonFormatter f)
 {
     f.BeginMap();
     return(new ActionDisposer(() => f.EndMap()));
 }