当前位置: 首页>>代码示例>>C#>>正文


C# JToken.OfType方法代码示例

本文整理汇总了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");
        }
开发者ID:JackWangCUMT,项目名称:docx-template-engine,代码行数:26,代码来源:Program.cs

示例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);
                }
            }

        }
开发者ID:nareshjo,项目名称:nodejstools,代码行数:9,代码来源:NpmGetCatalogCommand.cs

示例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;
         }
     }
 }
开发者ID:paladique,项目名称:nodejstools,代码行数:14,代码来源:NpmGetCatalogCommand.cs

示例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;
         }
     }
 }
开发者ID:klyuchnikov,项目名称:SystemMonitoringForTheLearningProcess,代码行数:53,代码来源:Model.cs

示例5: GetObjectOrEnum

 private static IEnumerable<JObject> GetObjectOrEnum (JToken jcontent)
 {
     return jcontent.Type == JTokenType.Object ? new[] { (JObject)jcontent } : jcontent.OfType<JObject>();
 }
开发者ID:Athari,项目名称:Alba.Jaml,代码行数:4,代码来源:XamlGenerator.cs


注:本文中的JToken.OfType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。