本文整理汇总了C#中JToken.Select方法的典型用法代码示例。如果您正苦于以下问题:C# JToken.Select方法的具体用法?C# JToken.Select怎么用?C# JToken.Select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JToken
的用法示例。
在下文中一共展示了JToken.Select方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ParseStates
public static List<State> ParseStates(JToken token)
{
if (token.Type == JTokenType.Object)
return new List<State> {
ParseState ((JProperty)token.First),
};
return token.Select (x => ParseState ((JProperty)x)).ToList ();
}
示例2: TransformToValue
private static object TransformToValue(JToken jToken)
{
switch (jToken.Type)
{
case JsonTokenType.Object:
return new DynamicJsonObject((JObject) jToken);
case JsonTokenType.Array:
return jToken.Select(TransformToValue).ToArray();
default:
return jToken.Value<object>();
}
}
示例3: ExtractValues
private static string[] ExtractValues(JToken json)
{
if (json.Type == JTokenType.String)
{
return new string[] { json.Value<string>() };
}
if (json.Type == JTokenType.Array)
{
return json.Select(v => v.ToString()).ToArray();
}
return new string[0];
}
示例4: ToObject
private static object ToObject(JToken token)
{
switch (token.Type)
{
case JTokenType.Object:
return token.Children<JProperty>()
.ToDictionary(prop => prop.Name,
prop => ToObject(prop.Value));
case JTokenType.Array:
return token.Select(ToObject).ToList();
default:
return ((JValue)token).Value;
}
}
示例5: Convert
public JsValue Convert(JToken token)
{
switch (token.Type)
{
case JTokenType.Array:
return Engine.Array.Construct(token.Select(Convert).ToArray());
case JTokenType.Boolean:
return new JsValue(token.Value<bool>());
case JTokenType.Bytes:
throw new NotSupportedException();
case JTokenType.Comment:
throw new NotSupportedException();
case JTokenType.Constructor:
throw new NotSupportedException();
case JTokenType.Date:
return Engine.Date.Construct(token.Value<DateTime>());
case JTokenType.Float:
return new JsValue(token.Value<float>());
case JTokenType.Guid:
throw new NotSupportedException();
case JTokenType.Integer:
return new JsValue(token.Value<int>());
case JTokenType.None:
throw new NotSupportedException();
case JTokenType.Null:
return JsValue.Null;
case JTokenType.Object:
return new NTSObjectInstance(Engine, (JObject)token);
case JTokenType.Property:
throw new NotSupportedException();
case JTokenType.Raw:
throw new NotSupportedException();
case JTokenType.String:
return new JsValue(token.Value<string>());
case JTokenType.TimeSpan:
throw new NotSupportedException();
case JTokenType.Undefined:
return JsValue.Undefined;
case JTokenType.Uri:
throw new NotSupportedException();
default:
throw new NotSupportedException();
}
}
示例6: TransformToValue
private static object TransformToValue(JToken jToken)
{
switch (jToken.Type)
{
case JTokenType.Object:
return new DynamicJsonObject((JObject) jToken);
case JTokenType.Array:
return jToken.Select(TransformToValue).ToArray();
default:
var value = jToken.Value<object>();
if(value is long)
{
var l = (long) value;
if(l > int.MinValue && int.MaxValue > l)
return (int) l;
}
return value;
}
}
示例7: CreateValue
private static object CreateValue(JToken token)
{
if (token.Type == JTokenType.Array)
{
return token.Select(x => x.Value<string>()).ToList();
}
else if (token.Type == JTokenType.Object)
{
return token
.Children<JProperty>()
.ToDictionary(x => x.Name, x => x.Value.Value<string>());
}
else if (token is JValue)
{
var value = token.Value<string>();
if (token.Type == JTokenType.Float)
{
value = value.Replace(',', '.');
}
return value;
}
else if (token.Type == JTokenType.Null)
{
return null;
}
throw new FormatException(string.Format("Unexpected type of varspec \"{0}\"", token.Type));
}
示例8: AddKeywords
private static void AddKeywords(NodeModuleBuilder builder, JToken keywords) {
if (keywords != null) {
foreach (var keyword in keywords.Select(v => (string)v)) {
builder.AddKeyword(keyword);
}
}
}
示例9: CreatePropertiesRecursively
private PropertyViewModel CreatePropertiesRecursively(string name, JToken json, BuilderContext context)
{
if (json is JArray)
{
int index=0;
ObservableCollection<ViewModel> array = new ObservableCollection<ViewModel>(json.Select(i => CreatePropertiesRecursively(string.Format("[{0}]",index++), i, context)));
return new ArrayPropertyViewModel(this, json, name, array);
}
else if (json is JObject)
{
return new ResourcePropertyViewModel(this, json, name, new ResourceViewModel(this, (JObject)json, context));
}
else
return new PropertyViewModel(this, json, name, (json != null ? json.ToString() : ""));
}
示例10: ConvertContentToChilds
private static List<Metadata> ConvertContentToChilds( JToken content, IQuatrixRequest request )
{
return content.Select( c => {
var mtd = c.ToObject<Metadata>();
mtd.Request = request;
return mtd;
} ).ToList();
}
示例11: Parse
public static StructuredText Parse(JToken json)
{
IList<Block> blocks = json.Select (r => ParseBlock(r)).Where(i => i != null).ToList ();
return new StructuredText(blocks);
}
示例12: ParseTimelines
static List<Timeline> ParseTimelines(JToken token)
{
if (token.Type == JTokenType.Object)
return new List<Timeline> {
ParseTimeline ((JProperty)token.First),
};
return token.Select (x => ParseTimeline ((JProperty)x)).ToList ();
}
示例13: TransformToValue
private static object TransformToValue(JToken jToken)
{
switch (jToken.Type)
{
case JTokenType.Object:
return new DynamicJsonObject((JObject) jToken);
case JTokenType.Array:
return jToken.Select(TransformToValue).ToArray();
default:
var value = jToken.Value<object>();
if(value is long)
{
var l = (long) value;
if(l > int.MinValue && int.MaxValue > l)
return (int) l;
}
var str = value as string;
if(str != null && str.StartsWith("0x"))
{
return JsonLuceneNumberConverter.ParseNumber(str);
}
return value;
}
}
示例14: PreencherListaStatements
/// <summary>
/// Cria o nó Body do Program
/// </summary>
/// <param name="jToken"></param>
/// <returns></returns>
private List<Statement> PreencherListaStatements(JToken jToken)
{
return jToken.Select(PreencherStatement).ToList();
}
示例15: ConvertTokenToDynamic
protected dynamic ConvertTokenToDynamic(JToken token)
{
// Strong types
if (token.Type == JTokenType.String) {
return (string)token;
}
if (token is JValue) {
return ((JValue)token).Value;
}
// Full object
if (token is JObject) {
var expando = new ExpandoObject();
var childTokens = (
from childToken in token
where childToken is JProperty
select childToken as JProperty
).ToList();
foreach (var property in childTokens) {
var value = ConvertTokenToDynamic(property.Value);
((IDictionary<string, object>)expando).Add(property.Name, value);
}
return expando;
}
// Array of properties possible?
// @TODO: Check if needed
if (token is JArray) {
return token.Select(arrayItem => ConvertTokenToDynamic(arrayItem)).ToList();
}
throw new ArgumentException(string.Format("Unknown token type '{0}'", token.GetType()), "token");
}