本文整理汇总了C#中JObject.CreateReader方法的典型用法代码示例。如果您正苦于以下问题:C# JObject.CreateReader方法的具体用法?C# JObject.CreateReader怎么用?C# JObject.CreateReader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JObject
的用法示例。
在下文中一共展示了JObject.CreateReader方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetTypeFromJObject
private IElasticCoreType GetTypeFromJObject(JObject po, JsonSerializer serializer)
{
JToken typeToken;
serializer.TypeNameHandling = TypeNameHandling.None;
if (po.TryGetValue("type", out typeToken))
{
var type = typeToken.Value<string>().ToLowerInvariant();
switch (type)
{
case "string":
return serializer.Deserialize(po.CreateReader(), typeof(StringMapping)) as StringMapping;
case "float":
case "double":
case "byte":
case "short":
case "integer":
case "long":
return serializer.Deserialize(po.CreateReader(), typeof(NumberMapping)) as NumberMapping;
case "date":
return serializer.Deserialize(po.CreateReader(), typeof(DateMapping)) as DateMapping;
case "boolean":
return serializer.Deserialize(po.CreateReader(), typeof(BooleanMapping)) as BooleanMapping;
case "binary":
return serializer.Deserialize(po.CreateReader(), typeof(BinaryMapping)) as BinaryMapping;
}
}
return null;
}
示例2: Example
public void Example()
{
#region Usage
JObject o = new JObject
{
{ "Cpu", "Intel" },
{ "Memory", 32 },
{
"Drives", new JArray
{
"DVD",
"SSD"
}
}
};
JsonReader reader = o.CreateReader();
while (reader.Read())
{
Console.Write(reader.TokenType);
if (reader.Value != null)
Console.Write(" - " + reader.Value);
Console.WriteLine();
}
// StartObject
// PropertyName - Cpu
// String - Intel
// PropertyName - Memory
// Integer - 32
// PropertyName - Drives
// StartArray
// String - DVD
// String - SSD
// EndArray
// EndObject
#endregion
}
示例3: GetTypeFromJObject
private IElasticType GetTypeFromJObject(JObject po, JsonSerializer serializer)
{
JToken typeToken;
JToken propertiesToken;
JToken fieldsToken;
var type = string.Empty;
var hasType = po.TryGetValue("type", out typeToken);
if (hasType)
type = typeToken.Value<string>().ToLowerInvariant();
else if (po.TryGetValue("properties", out propertiesToken))
type = "object";
var originalType = type;
var hasFields = po.TryGetValue("fields", out fieldsToken);
if (hasFields)
type = "multi_field";
serializer.TypeNameHandling = TypeNameHandling.None;
switch (type)
{
case "string":
return serializer.Deserialize(po.CreateReader(), typeof(StringMapping)) as StringMapping;
case "float":
case "double":
case "byte":
case "short":
case "integer":
case "long":
return serializer.Deserialize(po.CreateReader(), typeof(NumberMapping)) as NumberMapping;
case "date":
return serializer.Deserialize(po.CreateReader(), typeof(DateMapping)) as DateMapping;
case "boolean":
return serializer.Deserialize(po.CreateReader(), typeof(BooleanMapping)) as BooleanMapping;
case "binary":
return serializer.Deserialize(po.CreateReader(), typeof(BinaryMapping)) as BinaryMapping;
case "object":
return serializer.Deserialize(po.CreateReader(), typeof(ObjectMapping)) as ObjectMapping;
case "nested":
return serializer.Deserialize(po.CreateReader(), typeof(NestedObjectMapping)) as NestedObjectMapping;
case "multi_field":
var m =serializer.Deserialize(po.CreateReader(), typeof(MultiFieldMapping)) as MultiFieldMapping;
m.Type = originalType;
return m;
case "ip":
return serializer.Deserialize(po.CreateReader(), typeof(IPMapping)) as IPMapping;
case "geo_point":
return serializer.Deserialize(po.CreateReader(), typeof(GeoPointMapping)) as GeoPointMapping;
case "geo_shape":
return serializer.Deserialize(po.CreateReader(), typeof(GeoShapeMapping)) as GeoShapeMapping;
case "attachment":
return serializer.Deserialize(po.CreateReader(), typeof(AttachmentMapping)) as AttachmentMapping;
}
return null;
}