本文整理汇总了C#中JsonArray.SetAnnotation方法的典型用法代码示例。如果您正苦于以下问题:C# JsonArray.SetAnnotation方法的具体用法?C# JsonArray.SetAnnotation怎么用?C# JsonArray.SetAnnotation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JsonArray
的用法示例。
在下文中一共展示了JsonArray.SetAnnotation方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ParseArray
/// <summary>
/// Parses the token of type array
/// </summary>
/// <returns>Parsed array</returns>
private JsonArray ParseArray()
{
// Array can start only with '['
ExceptionUtilities.Assert(this.tokenizer.TokenType == JsonTokenType.LeftSquareBracket, "Invalid Token");
// Should not end before we get ']'
ExceptionUtilities.Assert(this.tokenizer.HasMoreTokens(), "Invalid End Of Stream");
var startArrayTextAnnotation = new JsonStartArrayTextAnnotation() { Text = this.tokenizer.TokenText };
this.tokenizer.GetNextToken();
// Array is an ordered collection of values
ExceptionUtilities.Assert(this.IsValueType(this.tokenizer.TokenType) || this.tokenizer.TokenType == JsonTokenType.RightSquareBracket, "InvalidToken");
var result = new JsonArray();
result.SetAnnotation(startArrayTextAnnotation);
JsonArrayElementSeparatorTextAnnotation arrayElementSeparatorTextAnnotation = null;
while (this.tokenizer.HasMoreTokens())
{
if (this.IsValueType(this.tokenizer.TokenType))
{
JsonValue v = this.ParseValue();
result.Add(v);
if (arrayElementSeparatorTextAnnotation != null)
{
v.SetAnnotation(arrayElementSeparatorTextAnnotation);
arrayElementSeparatorTextAnnotation = null;
}
// Values are separated by , (comma).
ExceptionUtilities.Assert(this.tokenizer.TokenType == JsonTokenType.Comma || this.tokenizer.TokenType == JsonTokenType.RightSquareBracket, "Invalid Token");
}
else if (this.tokenizer.TokenType == JsonTokenType.RightSquareBracket)
{
break;
}
else if (this.tokenizer.TokenType == JsonTokenType.Comma)
{
arrayElementSeparatorTextAnnotation = new JsonArrayElementSeparatorTextAnnotation() { Text = this.tokenizer.TokenText };
this.tokenizer.GetNextToken();
// Last element of the array cannot be followed by a comma.
ExceptionUtilities.Assert(this.IsValueType(this.tokenizer.TokenType) || this.tokenizer.TokenType == JsonTokenType.RightSquareBracket, "InvalidToken");
}
}
if (this.tokenizer.TokenType == JsonTokenType.RightSquareBracket)
{
result.SetAnnotation(new JsonEndArrayTextAnnotation() { Text = this.tokenizer.TokenText });
if (this.tokenizer.HasMoreTokens())
{
this.tokenizer.GetNextToken();
}
}
return result;
}