本文整理汇总了C#中JsonWriter.WriteUndefined方法的典型用法代码示例。如果您正苦于以下问题:C# JsonWriter.WriteUndefined方法的具体用法?C# JsonWriter.WriteUndefined怎么用?C# JsonWriter.WriteUndefined使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JsonWriter
的用法示例。
在下文中一共展示了JsonWriter.WriteUndefined方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ValueFormatting
public void ValueFormatting()
{
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
using (JsonWriter jsonWriter = new JsonWriter(sw))
{
jsonWriter.WriteStartArray();
jsonWriter.WriteValue('@');
jsonWriter.WriteValue("\r\n\t\f\b?{\\r\\n\"\'");
jsonWriter.WriteValue(true);
jsonWriter.WriteValue(10);
jsonWriter.WriteValue(10.99);
jsonWriter.WriteValue(0.99);
jsonWriter.WriteValue(0.000000000000000001d);
jsonWriter.WriteValue(0.000000000000000001m);
jsonWriter.WriteValue(null);
jsonWriter.WriteValue("This is a string.");
jsonWriter.WriteNull();
jsonWriter.WriteUndefined();
jsonWriter.WriteEndArray();
}
const string expected = @"[""@"",""\r\n\t\f\b?{\\r\\n\""'"",true,10,10.99,0.99,1E-18,0.000000000000000001,,""This is a string."",null,undefined]";
string result = sb.ToString();
Console.WriteLine("ValueFormatting");
Console.WriteLine(result);
Assert.AreEqual(expected, result);
}
示例2: WriteTo
/// <summary>
/// Writes this token to a <see cref="JsonWriter"/>.
/// </summary>
/// <param name="writer">A <see cref="JsonWriter"/> into which this method will write.</param>
/// <param name="converters">A collection of <see cref="JsonConverter"/> which will be used when writing the token.</param>
public override void WriteTo(JsonWriter writer, params JsonConverter[] converters)
{
switch (_valueType)
{
case JsonTokenType.Comment:
writer.WriteComment(_value.ToString());
break;
case JsonTokenType.Integer:
WriteConvertableValue(writer, converters, v => writer.WriteValue(Convert.ToInt64(v, CultureInfo.InvariantCulture)), _value);
break;
case JsonTokenType.Float:
WriteConvertableValue(writer, converters, v => writer.WriteValue(Convert.ToDouble(v, CultureInfo.InvariantCulture)), _value);
break;
case JsonTokenType.String:
WriteConvertableValue(writer, converters, v => writer.WriteValue(v.ToString()), _value);
break;
case JsonTokenType.Boolean:
WriteConvertableValue(writer, converters, v => writer.WriteValue(Convert.ToBoolean(v, CultureInfo.InvariantCulture)), _value);
break;
case JsonTokenType.Date:
WriteConvertableValue(writer, converters, v =>
{
if (v is DateTimeOffset)
writer.WriteValue((DateTimeOffset)v);
else
writer.WriteValue(Convert.ToDateTime(v, CultureInfo.InvariantCulture));
}, _value);
break;
case JsonTokenType.Raw:
writer.WriteRawValue(_value.ToString());
break;
case JsonTokenType.Null:
writer.WriteNull();
break;
case JsonTokenType.Undefined:
writer.WriteUndefined();
break;
default:
throw MiscellaneousUtils.CreateArgumentOutOfRangeException("TokenType", _valueType, "Unexpected token type.");
}
}
示例3: WriteTo
public override void WriteTo(JsonWriter writer)
{
switch (_valueType)
{
case JsonTokenType.Comment:
writer.WriteComment(_value.ToString());
break;
case JsonTokenType.Integer:
writer.WriteValue(Convert.ToInt64(_value));
break;
case JsonTokenType.Float:
writer.WriteValue(Convert.ToDouble(_value));
break;
case JsonTokenType.String:
writer.WriteValue(_value.ToString());
break;
case JsonTokenType.Boolean:
writer.WriteValue(Convert.ToBoolean(_value));
break;
case JsonTokenType.Null:
writer.WriteNull();
break;
case JsonTokenType.Undefined:
writer.WriteUndefined();
break;
case JsonTokenType.Date:
writer.WriteValue(Convert.ToDateTime(_value));
break;
default:
throw new ArgumentOutOfRangeException("TokenType", _valueType, "Unexpected token type.");
}
}