// -------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2014 OxyPlot contributors // // -------------------------------------------------------------------------------------------------------------------- namespace ExampleLibrary { using System; using System.Collections.Generic; using System.Linq; using System.Reflection; /// /// Enumerates all examples in the assembly. /// public static class Examples { /// /// Gets the list of examples. /// /// The list of examples. public static List GetList() { var list = new List(); var assemblyTypes = typeof(Examples).GetTypeInfo().Assembly.DefinedTypes; foreach (var type in assemblyTypes) { var examplesAttribute = type.GetCustomAttributes().FirstOrDefault(); if (examplesAttribute == null) { continue; } var examplesTags = type.GetCustomAttributes().FirstOrDefault() ?? new TagsAttribute(); var types = new List(); var baseType = type; while (baseType != null) { types.Add(baseType.AsType()); baseType = baseType.BaseType != null ? baseType.BaseType.GetTypeInfo() : null; } foreach (var t in types) { var methods = t.GetRuntimeMethods(); foreach (var method in methods) { try { var exampleAttribute = method.GetCustomAttributes().FirstOrDefault(); if (exampleAttribute != null) { var exampleTags = method.GetCustomAttributes().FirstOrDefault() ?? new TagsAttribute(); var tags = new List(examplesTags.Tags); tags.AddRange(exampleTags.Tags); list.Add( new ExampleInfo( examplesAttribute.Category, exampleAttribute.Title, tags.ToArray(), method)); } } catch (Exception) { } } } } return list; } } }