本文整理汇总了C#中JToken.CreateReader方法的典型用法代码示例。如果您正苦于以下问题:C# JToken.CreateReader方法的具体用法?C# JToken.CreateReader怎么用?C# JToken.CreateReader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JToken
的用法示例。
在下文中一共展示了JToken.CreateReader方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Validate
public static void Validate(JToken source, JsonSchema schema, ValidationEventHandler validationEventHandler)
{
ValidationUtils.ArgumentNotNull(source, "source");
ValidationUtils.ArgumentNotNull(schema, "schema");
using (JsonValidatingReader jsonValidatingReader = new JsonValidatingReader(source.CreateReader()))
{
jsonValidatingReader.Schema = schema;
if (validationEventHandler != null)
{
jsonValidatingReader.ValidationEventHandler += validationEventHandler;
}
while (jsonValidatingReader.Read())
{
}
}
}
示例2: ParseFacet
private Facet ParseFacet(JToken facet, string type, JsonReader reader, JsonSerializer serializer)
{
switch (type)
{
case "terms_stats":
var termStatistics = serializer.Deserialize<TermStatsFacet>(facet.CreateReader());
termStatistics.Key = termStatistics.Term;
return termStatistics;
case "geo_distance":
var geoDistance = serializer.Deserialize<GeoDistanceFacet>(facet.CreateReader());
geoDistance.Count = geoDistance.TotalCount;
geoDistance.Key = string.Format("From {0} to {1}", geoDistance.From, geoDistance.To);
return geoDistance;
case "statistical":
var statisticalFacet = serializer.Deserialize<StatisticalFacet>(facet.CreateReader());
statisticalFacet.Key = "__SingleFacet__";
return statisticalFacet;
case "terms":
var term = serializer.Deserialize<TermFacet>(facet.CreateReader());
term.Key = term.Term;
return term;
case "date_histogram":
var dateHistogram = serializer.Deserialize<DateHistogramFacet>(facet.CreateReader());
return dateHistogram;
case "histogram":
var histogram = serializer.Deserialize<HistogramFacet>(facet.CreateReader());
return histogram;
case "range":
if (((JObject)facet).Property("from_str") != null ||
((JObject)facet).Property("to_str") != null
)
{
var dateRange = serializer.Deserialize<DateRangeFacet>(facet.CreateReader());
dateRange.Key = string.Format("From {0} to {1}", dateRange.From, dateRange.To);
return dateRange;
}
var range = serializer.Deserialize<RangeFacet>(facet.CreateReader());
range.Key = string.Format("From {0} to {1}", range.From, range.To);
return range;
}
return null;
}
示例3: ReadData
private void ReadData(JToken data)
{
var reader = data.CreateReader();
string prevProperty = null;
var x = 0.0f;
var y = 0.0f;
while (reader.Read())
{
if (reader.Depth == 1 && reader.TokenType.ToString() == "PropertyName")
{
ActionName = (string)reader.Value;
}
else if (reader.TokenType.ToString() == "PropertyName")
{
prevProperty = reader.Value.ToString();
}
else if (prevProperty != null)
{
if (prevProperty == "pressed")
{
IsPressed = (bool)reader.Value;
}
else if (prevProperty == "x")
{
x = ReadFloat(reader);
}
else if (prevProperty == "y")
{
y = ReadFloat(reader) * -1;
}
prevProperty = null;
}
JoystickPosition = new Vector3(x, y);
}
}
示例4: CreateISerializableItem
internal object CreateISerializableItem(JToken token, Type type, JsonISerializableContract contract, JsonProperty member)
{
JsonContract itemContract = GetContractSafe(type);
JsonConverter itemConverter = GetConverter(itemContract, null, contract, member);
JsonReader tokenReader = token.CreateReader();
CheckedRead(tokenReader); // Move to first token
object result;
if (itemConverter != null && itemConverter.CanRead)
result = DeserializeConvertable(itemConverter, tokenReader, type, null);
else
result = CreateValueInternal(tokenReader, type, itemContract, null, contract, member, null);
return result;
}
示例5: TryJsonConverters
static bool TryJsonConverters(DeserializationContext context, Type type, JToken element, out object instance)
{
instance = null;
if (context.JsonConverters == null) return false;
var converter = context.JsonConverters.FirstOrDefault(c => c.CanConvert(type));
if (converter == null) return false;
using (var reader = element.CreateReader())
{
reader.Read();
instance = converter.ReadJson(reader, type, null, null);
return true;
}
}
示例6: Deserialize
private static object Deserialize(JsonSerializer serializer, JToken jtoken, ViewModelPropertyMap property, object existingValue)
{
if (property.JsonConverter != null && property.JsonConverter.CanRead && property.JsonConverter.CanConvert(property.Type))
{
return property.JsonConverter.ReadJson(jtoken.CreateReader(), property.Type, existingValue, serializer);
}
else if (existingValue != null && property.Populate)
{
if (jtoken.Type == JTokenType.Null)
return null;
else if (jtoken.Type == JTokenType.Object)
{
serializer.Converters.OfType<ViewModelJsonConverter>().First().Populate((JObject)jtoken, serializer, existingValue);
return existingValue;
}
else
{
serializer.Populate(jtoken.CreateReader(), existingValue);
return existingValue;
}
}
else
{
return serializer.Deserialize(jtoken.CreateReader(), property.Type);
}
}
示例7: CreateReader
private static JsonReader CreateReader(JToken token)
{
JsonReader reader = token.CreateReader();
bool read = reader.Read();
Assert.True(read);
return reader;
}
示例8: CreateISerializableItem
// Token: 0x06000BD6 RID: 3030
// RVA: 0x00045708 File Offset: 0x00043908
internal object CreateISerializableItem(JToken token, Type type, JsonISerializableContract contract, JsonProperty member)
{
JsonContract contractSafe = this.GetContractSafe(type);
JsonConverter converter = this.GetConverter(contractSafe, null, contract, member);
JsonReader reader = token.CreateReader();
this.CheckedRead(reader);
object result;
if (converter != null && converter.CanRead)
{
result = this.DeserializeConvertable(converter, reader, type, null);
}
else
{
result = this.CreateValueInternal(reader, type, contractSafe, null, contract, member, null);
}
return result;
}