本文整理汇总了C#中JArray.Count方法的典型用法代码示例。如果您正苦于以下问题:C# JArray.Count方法的具体用法?C# JArray.Count怎么用?C# JArray.Count使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JArray
的用法示例。
在下文中一共展示了JArray.Count方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddBeforeSelf
public void AddBeforeSelf()
{
JArray a =
new JArray(
5,
new JArray(1),
new JArray(1, 2),
new JArray(1, 2, 3)
);
a[1].AddBeforeSelf("pie");
Assert.AreEqual(5, (int)a[0]);
Assert.AreEqual("pie", (string)a[1]);
Assert.AreEqual(a, a[1].Parent);
Assert.AreEqual(a[2], a[1].Next);
Assert.AreEqual(5, a.Count());
a[0].AddBeforeSelf("firstpie");
Assert.AreEqual("firstpie", (string)a[0]);
Assert.AreEqual(5, (int)a[1]);
Assert.AreEqual("pie", (string)a[2]);
Assert.AreEqual(a, a[0].Parent);
Assert.AreEqual(a[1], a[0].Next);
Assert.AreEqual(6, a.Count());
a.Last.AddBeforeSelf("secondlastpie");
Assert.AreEqual("secondlastpie", (string)a[5]);
Assert.AreEqual(7, a.Count());
}
示例2: CreateJTokenTree
public void CreateJTokenTree()
{
JObject o =
new JObject(
new JProperty("Test1", "Test1Value"),
new JProperty("Test2", "Test2Value"),
new JProperty("Test3", "Test3Value"),
new JProperty("Test4", null)
);
Assert.AreEqual(4, o.Properties().Count());
Assert.AreEqual(@"{
""Test1"": ""Test1Value"",
""Test2"": ""Test2Value"",
""Test3"": ""Test3Value"",
""Test4"": null
}", o.ToString());
JArray a =
new JArray(
o,
new DateTime(2000, 10, 10, 0, 0, 0, DateTimeKind.Utc),
55,
new JArray(
"1",
2,
3.0,
new DateTime(4, 5, 6, 7, 8, 9, DateTimeKind.Utc)
),
new JConstructor(
"ConstructorName",
"param1",
2,
3.0
)
);
Assert.AreEqual(5, a.Count());
Assert.AreEqual(@"[
{
""Test1"": ""Test1Value"",
""Test2"": ""Test2Value"",
""Test3"": ""Test3Value"",
""Test4"": null
},
""2000-10-10T00:00:00Z"",
55,
[
""1"",
2,
3.0,
""0004-05-06T07:08:09Z""
],
new ConstructorName(
""param1"",
2,
3.0
)
]", a.ToString());
}
示例3: Replace
public void Replace()
{
JArray a =
new JArray(
5,
new JArray(1),
new JArray(1, 2),
new JArray(1, 2, 3)
);
a[0].Replace(new JValue(int.MaxValue));
Assert.AreEqual(int.MaxValue, (int)a[0]);
Assert.AreEqual(4, a.Count());
a[1][0].Replace(new JValue("Test"));
Assert.AreEqual("Test", (string)a[1][0]);
a[2].Replace(new JValue(int.MaxValue));
Assert.AreEqual(int.MaxValue, (int)a[2]);
Assert.AreEqual(4, a.Count());
Assert.IsTrue(JToken.DeepEquals(new JArray(int.MaxValue, new JArray("Test"), int.MaxValue, new JArray(1, 2, 3)), a));
}
示例4: AddAfterSelf
public void AddAfterSelf()
{
JArray a =
new JArray(
5,
new JArray(1),
new JArray(1, 2),
new JArray(1, 2, 3)
);
a[1].AddAfterSelf("pie");
Assert.AreEqual(5, (int)a[0]);
Assert.AreEqual(1, a[1].Count());
Assert.AreEqual("pie", (string)a[2]);
Assert.AreEqual(5, a.Count());
a[4].AddAfterSelf("lastpie");
Assert.AreEqual("lastpie", (string)a[5]);
Assert.AreEqual("lastpie", (string)a.Last);
}
示例5: RemoveAll
public void RemoveAll()
{
JArray a =
new JArray(
5,
new JArray(1),
new JArray(1, 2),
new JArray(1, 2, 3)
);
JToken first = a.First;
Assert.AreEqual(5, (int)first);
a.RemoveAll();
Assert.AreEqual(0, a.Count());
Assert.IsNull(first.Parent);
Assert.IsNull(first.Next);
}
示例6: AddFirst
public void AddFirst()
{
JArray a =
new JArray(
5,
new JArray(1),
new JArray(1, 2),
new JArray(1, 2, 3)
);
a.AddFirst("First");
Assert.AreEqual("First", (string)a[0]);
Assert.AreEqual(a, a[0].Parent);
Assert.AreEqual(a[1], a[0].Next);
Assert.AreEqual(5, a.Count());
a.AddFirst("NewFirst");
Assert.AreEqual("NewFirst", (string)a[0]);
Assert.AreEqual(a, a[0].Parent);
Assert.AreEqual(a[1], a[0].Next);
Assert.AreEqual(6, a.Count());
Assert.AreEqual(a[0], a[0].Next.Previous);
}
示例7: CreateWriter
public void CreateWriter()
{
JArray a =
new JArray(
5,
new JArray(1),
new JArray(1, 2),
new JArray(1, 2, 3)
);
JsonWriter writer = a.CreateWriter();
Assert.IsNotNull(writer);
Assert.AreEqual(4, a.Count());
writer.WriteValue("String");
Assert.AreEqual(5, a.Count());
Assert.AreEqual("String", (string)a[4]);
writer.WriteStartObject();
writer.WritePropertyName("Property");
writer.WriteValue("PropertyValue");
writer.WriteEnd();
Assert.AreEqual(6, a.Count());
Assert.IsTrue(JToken.DeepEquals(new JObject(new JProperty("Property", "PropertyValue")), a[5]));
}
示例8: Remove
public void Remove()
{
JToken t;
JArray a =
new JArray(
5,
6,
new JArray(7, 8),
new JArray(9, 10)
);
a[0].Remove();
Assert.AreEqual(6, (int)a[0]);
a[1].Remove();
Assert.AreEqual(6, (int)a[0]);
Assert.IsTrue(JToken.DeepEquals(new JArray(9, 10), a[1]));
Assert.AreEqual(2, a.Count());
t = a[1];
t.Remove();
Assert.AreEqual(6, (int)a[0]);
Assert.IsNull(t.Next);
Assert.IsNull(t.Previous);
Assert.IsNull(t.Parent);
t = a[0];
t.Remove();
Assert.AreEqual(0, a.Count());
Assert.IsNull(t.Next);
Assert.IsNull(t.Previous);
Assert.IsNull(t.Parent);
}
示例9: Children
public void Children()
{
JArray a =
new JArray(
5,
new JArray(1),
new JArray(1, 2),
new JArray(1, 2, 3)
);
Assert.AreEqual(4, a.Count());
Assert.AreEqual(3, a.Children<JArray>().Count());
}