本文整理汇总了C#中JToken.OfType方法的典型用法代码示例。如果您正苦于以下问题:C# JToken.OfType方法的具体用法?C# JToken.OfType怎么用?C# JToken.OfType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JToken
的用法示例。
在下文中一共展示了JToken.OfType方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: JsonToDynamic
static dynamic JsonToDynamic(JToken token)
{
if (token is JValue) return ((JValue)token).Value;
if (token is JObject)
{
var expando = new ExpandoObject();
foreach (var childToken in token.OfType<JProperty>())
{
((IDictionary<string, object>)expando).Add(childToken.Name, JsonToDynamic(childToken.Value));
}
return expando;
}
if (token is JArray)
{
var items = new List<ExpandoObject>();
foreach (var arrayItem in ((JArray)token))
{
items.Add(JsonToDynamic(arrayItem));
}
return items;
}
throw new ArgumentException(string.Format("Unknown token type {0}", token.GetType()), "token");
}
示例2: GetVersions
private IEnumerable<SemverVersion> GetVersions(JToken versionsToken) {
IEnumerable<string> versionStrings = versionsToken.OfType<JProperty>().Select(v => (string)v.Name);
foreach (var versionString in versionStrings) {
if (!string.IsNullOrEmpty(versionString)) {
yield return SemverVersion.Parse(versionString);
}
}
}
示例3: GetVersions
private IEnumerable<SemverVersion> GetVersions(JToken versionsToken) {
var versionStrings = versionsToken.OfType<JProperty>().Select(v => (string)v.Name);
foreach (var versionString in versionStrings) {
if (!string.IsNullOrEmpty(versionString)) {
SemverVersion ver;
try {
ver = SemverVersion.Parse(versionString);
} catch (SemverVersionFormatException) {
continue;
}
yield return ver;
}
}
}
示例4: Load
public void Load(JToken jToken)
{
var arr = jToken.OfType<JProperty>().ToArray();
foreach (var jProperty in arr)
{
switch (jProperty.Name)
{
case "Groups":
Model.Group.AddRangeGroup(jProperty.Value as JArray);
break;
case "Disciplines":
Model.Discipline.AddRangeDiscipline(jProperty.Value as JArray);
break;
case "Students":
Model.Student.AddRangeStudent(jProperty.Value as JArray);
break;
case "HistoriesStudents":
Model.HistoryStudent.AddRangeHistoryStudent(jProperty.Value as JArray);
break;
case "Teachers":
Model.Teacher.AddRangeTeacher(jProperty.Value as JArray);
CurrentTeacher = null;
break;
case "Statuses":
Model.Status.AddRangeStatus(jProperty.Value as JArray);
break;
case "TypesWorks":
Model.TypeWork.AddRangeTypeWork(jProperty.Value as JArray);
break;
case "DisciplinesGroupses":
Model.DisciplinesGroups.AddRangeDisciplinesGroups(jProperty.Value as JArray);
break;
case "CommentsDisciplineForStudent":
Model.CommentDisciplineForStudent.AddRangeCommentDisciplineForStudent(jProperty.Value as JArray);
break;
case "DisciplinesTeachersTypeWorks":
Model.DisciplinesTeachersTypeWork.AddRangeDisciplinesTeachersTypeWork(jProperty.Value as JArray);
break;
case "Works":
Model.Work.AddRangeWork(jProperty.Value as JArray);
break;
case "PassingWorks":
Model.PassingWork.AddRangePassingWork(jProperty.Value as JArray);
break;
case "AttendingsLectures":
Model.AttendingLectures.AddRangeAttendingLectures(jProperty.Value as JArray);
break;
case "DisciplinesTeacherses":
Model.DisciplinesTeachers.AddRangeDisciplinesTeachers(jProperty.Value as JArray);
break;
}
}
}
示例5: GetObjectOrEnum
private static IEnumerable<JObject> GetObjectOrEnum (JToken jcontent)
{
return jcontent.Type == JTokenType.Object ? new[] { (JObject)jcontent } : jcontent.OfType<JObject>();
}