当前位置: 首页>>代码示例>>C#>>正文


C# JObject.Children方法代码示例

本文整理汇总了C#中JObject.Children方法的典型用法代码示例。如果您正苦于以下问题:C# JObject.Children方法的具体用法?C# JObject.Children怎么用?C# JObject.Children使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在JObject的用法示例。


在下文中一共展示了JObject.Children方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Remove

    public void Remove()
    {
      JObject o = new JObject();
      o.Add("PropertyNameValue", new JValue(1));
      Assert.AreEqual(1, o.Children().Count());

      Assert.AreEqual(false, o.Remove("sdf"));
      Assert.AreEqual(false, o.Remove(null));
      Assert.AreEqual(true, o.Remove("PropertyNameValue"));

      Assert.AreEqual(0, o.Children().Count());
    }
开发者ID:bitpusher,项目名称:Newtonsoft.Json4,代码行数:12,代码来源:JObjectTests.cs

示例2: DictionaryItemShouldSet

    public void DictionaryItemShouldSet()
    {
      JObject o = new JObject();
      o["PropertyNameValue"] = new JValue(1);
      Assert.AreEqual(1, o.Children().Count());

      JToken t;
      Assert.AreEqual(true, o.TryGetValue("PropertyNameValue", out t));
      Assert.AreEqual(true, JToken.DeepEquals(new JValue(1), t));

      o["PropertyNameValue"] = new JValue(2);
      Assert.AreEqual(1, o.Children().Count());

      Assert.AreEqual(true, o.TryGetValue("PropertyNameValue", out t));
      Assert.AreEqual(true, JToken.DeepEquals(new JValue(2), t));

      o["PropertyNameValue"] = null;
      Assert.AreEqual(1, o.Children().Count());

      Assert.AreEqual(true, o.TryGetValue("PropertyNameValue", out t));
      Assert.AreEqual(true, JToken.DeepEquals(new JValue((object)null), t));
    }
开发者ID:bitpusher,项目名称:Newtonsoft.Json4,代码行数:22,代码来源:JObjectTests.cs

示例3: WriteSettingObject

		private void WriteSettingObject(JsonWriter writer, JObject obj)
		{
			writer.WriteStartObject();
			foreach (var property in obj.Children<JProperty>())
			{
				writer.WritePropertyName(property.Name);
				if (property.Value is JObject)
					this.WriteSettingObject(writer, property.Value as JObject);
				else
					writer.WriteValue(property.Value);
			}
			writer.WriteEndObject();

		}
开发者ID:modulexcite,项目名称:Transformalize,代码行数:14,代码来源:IndexSettingsConverter.cs

示例4: GenericCollectionRemove

    public void GenericCollectionRemove()
    {
      JValue v = new JValue(1);
      JObject o = new JObject();
      o.Add("PropertyNameValue", v);
      Assert.AreEqual(1, o.Children().Count());

      Assert.AreEqual(false, ((ICollection<KeyValuePair<string, JToken>>)o).Remove(new KeyValuePair<string, JToken>("PropertyNameValue1", new JValue(1))));
      Assert.AreEqual(false, ((ICollection<KeyValuePair<string, JToken>>)o).Remove(new KeyValuePair<string, JToken>("PropertyNameValue", new JValue(2))));
      Assert.AreEqual(false, ((ICollection<KeyValuePair<string, JToken>>)o).Remove(new KeyValuePair<string, JToken>("PropertyNameValue", new JValue(1))));
      Assert.AreEqual(true, ((ICollection<KeyValuePair<string, JToken>>)o).Remove(new KeyValuePair<string, JToken>("PropertyNameValue", v)));

      Assert.AreEqual(0, o.Children().Count());
    }
开发者ID:bitpusher,项目名称:Newtonsoft.Json4,代码行数:14,代码来源:JObjectTests.cs

示例5: TryGetValue

    public void TryGetValue()
    {
      JObject o = new JObject();
      o.Add("PropertyNameValue", new JValue(1));
      Assert.AreEqual(1, o.Children().Count());

      JToken t;
      Assert.AreEqual(false, o.TryGetValue("sdf", out t));
      Assert.AreEqual(null, t);

      Assert.AreEqual(false, o.TryGetValue(null, out t));
      Assert.AreEqual(null, t);

      Assert.AreEqual(true, o.TryGetValue("PropertyNameValue", out t));
      Assert.AreEqual(true, JToken.DeepEquals(new JValue(1), t));
    }
开发者ID:bitpusher,项目名称:Newtonsoft.Json4,代码行数:16,代码来源:JObjectTests.cs

示例6: GenericCollectionCopyTo

        public void GenericCollectionCopyTo()
        {
            var o = new JObject();
            o.Add("PropertyNameValue", new JValue(1));
            o.Add("PropertyNameValue2", new JValue(2));
            o.Add("PropertyNameValue3", new JValue(3));
            Assert.Equal(3, o.Children().Count());

            KeyValuePair<string, JToken>[] a = new KeyValuePair<string, JToken>[5];

            ((ICollection<KeyValuePair<string, JToken>>)o).CopyTo(a, 1);

            Assert.Equal(default(KeyValuePair<string, JToken>), a[0]);

            Assert.Equal("PropertyNameValue", a[1].Key);
            Assert.Equal(1, (int)a[1].Value);

            Assert.Equal("PropertyNameValue2", a[2].Key);
            Assert.Equal(2, (int)a[2].Value);

            Assert.Equal("PropertyNameValue3", a[3].Key);
            Assert.Equal(3, (int)a[3].Value);

            Assert.Equal(default(KeyValuePair<string, JToken>), a[4]);
        }
开发者ID:extesla,项目名称:OpenGamingLibrary,代码行数:25,代码来源:JObjectTests.cs

示例7: GenericDictionaryContains

        public void GenericDictionaryContains()
        {
            var o = new JObject();
            o.Add("PropertyNameValue", new JValue(1));
            Assert.Equal(1, o.Children().Count());

            bool contains = ((IDictionary<string, JToken>)o).ContainsKey("PropertyNameValue");
            Assert.Equal(true, contains);
        }
开发者ID:extesla,项目名称:OpenGamingLibrary,代码行数:9,代码来源:JObjectTests.cs

示例8: GenericCollectionContains

        public void GenericCollectionContains()
        {
            JValue v = new JValue(1);
            var o = new JObject();
            o.Add("PropertyNameValue", v);
            Assert.Equal(1, o.Children().Count());

            bool contains = ((ICollection<KeyValuePair<string, JToken>>)o).Contains(new KeyValuePair<string, JToken>("PropertyNameValue", new JValue(1)));
            Assert.Equal(false, contains);

            contains = ((ICollection<KeyValuePair<string, JToken>>)o).Contains(new KeyValuePair<string, JToken>("PropertyNameValue", v));
            Assert.Equal(true, contains);

            contains = ((ICollection<KeyValuePair<string, JToken>>)o).Contains(new KeyValuePair<string, JToken>("PropertyNameValue", new JValue(2)));
            Assert.Equal(false, contains);

            contains = ((ICollection<KeyValuePair<string, JToken>>)o).Contains(new KeyValuePair<string, JToken>("PropertyNameValue1", new JValue(1)));
            Assert.Equal(false, contains);

            contains = ((ICollection<KeyValuePair<string, JToken>>)o).Contains(default(KeyValuePair<string, JToken>));
            Assert.Equal(false, contains);
        }
开发者ID:extesla,项目名称:OpenGamingLibrary,代码行数:22,代码来源:JObjectTests.cs

示例9: GenericCollectionClear

        public void GenericCollectionClear()
        {
            var o = new JObject();
            o.Add("PropertyNameValue", new JValue(1));
            Assert.Equal(1, o.Children().Count());

            JProperty p = (JProperty)o.Children().ElementAt(0);

            ((ICollection<KeyValuePair<string, JToken>>)o).Clear();
            Assert.Equal(0, o.Children().Count());

            Assert.Equal(null, p.Parent);
        }
开发者ID:extesla,项目名称:OpenGamingLibrary,代码行数:13,代码来源:JObjectTests.cs

示例10: GenericCollectionAdd

        public void GenericCollectionAdd()
        {
            var o = new JObject();
            ((ICollection<KeyValuePair<string, JToken>>)o).Add(new KeyValuePair<string, JToken>("PropertyNameValue", new JValue(1)));

            Assert.Equal(1, (int)o["PropertyNameValue"]);
            Assert.Equal(1, o.Children().Count());
        }
开发者ID:extesla,项目名称:OpenGamingLibrary,代码行数:8,代码来源:JObjectTests.cs

示例11: GenericDictionaryAdd

        public void GenericDictionaryAdd()
        {
            var o = new JObject();

            o.Add("PropertyNameValue", new JValue(1));
            Assert.Equal(1, (int)o["PropertyNameValue"]);

            o.Add("PropertyNameValue1", null);
            Assert.Equal(null, ((JValue)o["PropertyNameValue1"]).Value);

            Assert.Equal(2, o.Children().Count());
        }
开发者ID:extesla,项目名称:OpenGamingLibrary,代码行数:12,代码来源:JObjectTests.cs


注:本文中的JObject.Children方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。