-
Notifications
You must be signed in to change notification settings - Fork 2
/
MarkdownTemplate.cs
115 lines (98 loc) · 3.94 KB
/
MarkdownTemplate.cs
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
namespace UsageRateTool
{
class MarkdownTemplate
{
public static void Print(IEnumerable<API> apis)
{
var apiProperty = typeof(API).GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly)
.Where(p => Attribute.IsDefined(p, typeof(PrintableAttribute)))
.OrderBy(p => (p?.GetCustomAttribute(typeof(PrintableAttribute), false) as PrintableAttribute)?.Order);
int targetCount = 0;
int UsedCount = 0;
Dictionary<string, int> maxSize = new Dictionary<string, int>();
foreach (var property in apiProperty)
{
maxSize[property.Name] = property.Name.Length;
}
foreach (var api in apis)
{
if (api.Parent != API.Empty)
targetCount++;
if (api.Caller.Count() > 0) UsedCount++;
foreach (var property in apiProperty)
{
object v = property.GetValue(api);
string vstr = v == null ? "" : v.ToString();
if (maxSize[property.Name] < vstr.Length)
{
maxSize[property.Name] = vstr.Length;
}
}
}
Console.WriteLine($"public API has used {UsedCount} / {targetCount}");
var types = apis.Where(m => m.Category == Category.Type);
foreach (var type in types)
{
Console.WriteLine();
Console.WriteLine($"## {type.Name}");
Console.WriteLine();
var members = apis.Where(m => m.Parent == type);
if (members.Count() == 0)
{
Console.WriteLine("There are no newly defined members in this type.");
continue;
}
Console.Write("|");
foreach (var property in apiProperty)
{
Console.Write(String.Format($" {{0, -{maxSize[property.Name]}}} |", property.Name));
}
Console.WriteLine();
Console.Write("|");
foreach (var property in apiProperty)
{
Console.Write(String.Format($" {{0, -{maxSize[property.Name]}}} |", "".PadLeft(maxSize[property.Name], '-')));
}
Console.WriteLine();
foreach (var m in members)
{
Console.Write("|");
foreach (var property in apiProperty)
{
var v = property.GetValue(m);
string vstr = v == null ? "" : v.ToString();
Console.Write(String.Format($" {{0, -{maxSize[property.Name]}}} |", vstr));
}
Console.WriteLine();
}
}
Console.WriteLine("----");
Console.WriteLine();
Console.WriteLine("## API Cross references");
Console.WriteLine();
foreach (var api in apis)
{
if (api.Caller.Count() < 1)
{
continue;
}
Console.WriteLine($"### {api.DeclaredType}.{api.Name}");
foreach (var reference in api.Caller)
{
Console.WriteLine($" - {reference.DeclaringType.Namespace}.{reference.DeclaringType.Name} / {reference}");
}
Console.WriteLine();
}
Console.WriteLine();
Console.WriteLine("----");
Console.WriteLine();
Console.WriteLine("This document was created at https://github.com/idkiller/UsageRateTool.git");
Console.WriteLine();
}
}
}