本文整理汇总了C#中JsonReader.ReadAndMoveToContent方法的典型用法代码示例。如果您正苦于以下问题:C# JsonReader.ReadAndMoveToContent方法的具体用法?C# JsonReader.ReadAndMoveToContent怎么用?C# JsonReader.ReadAndMoveToContent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JsonReader
的用法示例。
在下文中一共展示了JsonReader.ReadAndMoveToContent方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateJObject
private JToken CreateJObject(JsonReader reader)
{
ValidationUtils.ArgumentNotNull(reader, nameof(reader));
// this is needed because we've already read inside the object, looking for metadata properties
using (JTokenWriter writer = new JTokenWriter())
{
writer.WriteStartObject();
do
{
if (reader.TokenType == JsonToken.PropertyName)
{
string propertyName = (string)reader.Value;
if (!reader.ReadAndMoveToContent())
{
break;
}
if (CheckPropertyName(reader, propertyName))
{
continue;
}
writer.WritePropertyName(propertyName);
writer.WriteToken(reader, true, true, false);
}
else if (reader.TokenType == JsonToken.Comment)
{
// eat
}
else
{
writer.WriteEndObject();
return writer.Token;
}
} while (reader.Read());
throw JsonSerializationException.Create(reader, "Unexpected end when deserializing object.");
}
}
示例2: ReadForType
private bool ReadForType(JsonReader reader, JsonContract contract, bool hasConverter)
{
// don't read properties with converters as a specific value
// the value might be a string which will then get converted which will error if read as date for example
if (hasConverter)
{
return reader.Read();
}
ReadType t = (contract != null) ? contract.InternalReadType : ReadType.Read;
switch (t)
{
case ReadType.Read:
return reader.ReadAndMoveToContent();
case ReadType.ReadAsInt32:
reader.ReadAsInt32();
break;
case ReadType.ReadAsDecimal:
reader.ReadAsDecimal();
break;
case ReadType.ReadAsDouble:
reader.ReadAsDouble();
break;
case ReadType.ReadAsBytes:
reader.ReadAsBytes();
break;
case ReadType.ReadAsBoolean:
reader.ReadAsBoolean();
break;
case ReadType.ReadAsString:
reader.ReadAsString();
break;
case ReadType.ReadAsDateTime:
reader.ReadAsDateTime();
break;
#if !NET20
case ReadType.ReadAsDateTimeOffset:
reader.ReadAsDateTimeOffset();
break;
#endif
default:
throw new ArgumentOutOfRangeException();
}
return (reader.TokenType != JsonToken.None);
}