forked from oxyplot/oxyplot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExamples.cs
More file actions
60 lines (53 loc) · 2.13 KB
/
Copy pathExamples.cs
File metadata and controls
60 lines (53 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="Examples.cs" company="OxyPlot">
// Copyright (c) 2014 OxyPlot contributors
// </copyright>
// --------------------------------------------------------------------------------------------------------------------
namespace ExampleLibrary
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
public static class Examples
{
public static List<ExampleInfo> GetList()
{
var list = new List<ExampleInfo>();
var assemblyTypes = typeof(Examples).Assembly.GetTypes();
foreach (var type in assemblyTypes)
{
var examplesAttributes = type.GetCustomAttributes(typeof(ExamplesAttribute), true).ToArray();
if (examplesAttributes.Length == 0)
{
continue;
}
var examplesAttribute = examplesAttributes[0] as ExamplesAttribute;
var types = new List<Type>();
var baseType = type;
while (baseType != null)
{
types.Add(baseType);
baseType = baseType.BaseType;
}
foreach (var t in types)
{
foreach (var method in t.GetMethods(BindingFlags.Public | BindingFlags.Static))
{
var exampleAttributes = method.GetCustomAttributes(typeof(ExampleAttribute), true);
if (exampleAttributes.Length == 0)
{
continue;
}
var exampleAttribute = (ExampleAttribute)exampleAttributes[0];
if (examplesAttribute != null)
{
list.Add(new ExampleInfo(examplesAttribute.Category, exampleAttribute.Title, method));
}
}
}
}
return list;
}
}
}