Пример #1
0
        public void MergeNull()
        {
            JConstructor c = new JConstructor();
            c.Merge(null);
            Assert.AreEqual(null, c.Name);
            Assert.AreEqual(0, c.Count);

            JObject o = new JObject();
            o.Merge(null);
            Assert.AreEqual(0, o.Count);

            JArray a = new JArray();
            a.Merge(null);
            Assert.AreEqual(0, a.Count);

            JProperty p = new JProperty("name1");
            p.Merge(null);
            Assert.AreEqual("name1", p.Name);
            Assert.AreEqual(0, p.Count);
        }
Пример #2
0
 /// <summary>
 /// Merge zweier Arrays
 /// </summary>
 /// <param name="iTarget"></param>
 /// <param name="iTemplate"></param>
 private void MergeTemplate(JArray iTarget, JArray iTemplate) {
     JsonMergeSettings lMergeSettings = new JsonMergeSettings();
     lMergeSettings.MergeArrayHandling = MergeArrayHandling.Union;
     if (iTemplate.First.Type == JTokenType.Array) {
         for (int i = 0; i < iTemplate.Count && i < iTarget.Count; i++) {
             //(iTarget[i] as JArray).Merge(iTemplate[i], lMergeSettings);
             //iTemplate[i].Remove();
             (iTemplate[i] as JArray).Merge(iTarget[i], lMergeSettings);
             iTarget[i].Remove();
         }
     }
     //iTarget.Merge(iTemplate, lMergeSettings);
     iTemplate.Merge(iTarget, lMergeSettings);
     iTarget.RemoveAll();
     iTarget.Add(iTemplate.Children());
 }