本文整理汇总了C#中Newtonsoft.Json.Linq.JTokenReader.ReadAndAssert方法的典型用法代码示例。如果您正苦于以下问题:C# JTokenReader.ReadAndAssert方法的具体用法?C# JTokenReader.ReadAndAssert怎么用?C# JTokenReader.ReadAndAssert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Newtonsoft.Json.Linq.JTokenReader
的用法示例。
在下文中一共展示了JTokenReader.ReadAndAssert方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadMetadataPropertiesToken
private bool ReadMetadataPropertiesToken(JTokenReader reader, ref Type objectType, ref JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, object existingValue, out object newValue, out string id)
{
id = null;
newValue = null;
if (reader.TokenType == JsonToken.StartObject)
{
JObject current = (JObject)reader.CurrentToken;
JToken refToken = current[JsonTypeReflector.RefPropertyName];
if (refToken != null)
{
if (refToken.Type != JTokenType.String && refToken.Type != JTokenType.Null)
{
throw JsonSerializationException.Create(refToken, refToken.Path, "JSON reference {0} property must have a string or null value.".FormatWith(CultureInfo.InvariantCulture, JsonTypeReflector.RefPropertyName), null);
}
JToken property = refToken.Parent;
JToken additionalContent = null;
if (property.Next != null)
{
additionalContent = property.Next;
}
else if (property.Previous != null)
{
additionalContent = property.Previous;
}
string reference = (string)refToken;
if (reference != null)
{
if (additionalContent != null)
{
throw JsonSerializationException.Create(additionalContent, additionalContent.Path, "Additional content found in JSON reference object. A JSON reference object should only have a {0} property.".FormatWith(CultureInfo.InvariantCulture, JsonTypeReflector.RefPropertyName), null);
}
newValue = Serializer.GetReferenceResolver().ResolveReference(this, reference);
if (TraceWriter != null && TraceWriter.LevelFilter >= TraceLevel.Info)
{
TraceWriter.Trace(TraceLevel.Info, JsonPosition.FormatMessage(reader as IJsonLineInfo, reader.Path, "Resolved object reference '{0}' to {1}.".FormatWith(CultureInfo.InvariantCulture, reference, newValue.GetType())), null);
}
reader.Skip();
return true;
}
}
JToken typeToken = current[JsonTypeReflector.TypePropertyName];
if (typeToken != null)
{
string qualifiedTypeName = (string)typeToken;
JsonReader typeTokenReader = typeToken.CreateReader();
typeTokenReader.ReadAndAssert();
ResolveTypeName(typeTokenReader, ref objectType, ref contract, member, containerContract, containerMember, qualifiedTypeName);
JToken valueToken = current[JsonTypeReflector.ValuePropertyName];
if (valueToken != null)
{
while (true)
{
reader.ReadAndAssert();
if (reader.TokenType == JsonToken.PropertyName)
{
if ((string)reader.Value == JsonTypeReflector.ValuePropertyName)
{
return false;
}
}
reader.ReadAndAssert();
reader.Skip();
}
}
}
JToken idToken = current[JsonTypeReflector.IdPropertyName];
if (idToken != null)
{
id = (string)idToken;
}
JToken valuesToken = current[JsonTypeReflector.ArrayValuesPropertyName];
if (valuesToken != null)
{
JsonReader listReader = valuesToken.CreateReader();
listReader.ReadAndAssert();
newValue = CreateList(listReader, objectType, contract, member, existingValue, id);
reader.Skip();
return true;
}
}
reader.ReadAndAssert();
return false;
}