|
14 | 14 |
|
15 | 15 |
|
16 | 16 |
|
17 |
| -namespace DoofesZeug.Documentation |
| 17 | +namespace DoofesZeug.Documentation; |
| 18 | + |
| 19 | +public static class GenerateEnumerationsOverview |
18 | 20 | {
|
19 |
| - public static class GenerateEnumerationsOverview |
20 |
| - { |
21 |
| - private static readonly string OUTPUTDIRECTORY = @"O:\DoofesZeug\Documentation\Generated\Enumerations"; |
| 21 | + private static readonly string OUTPUTDIRECTORY = @"O:\DoofesZeug\Documentation\Generated\Enumerations"; |
22 | 22 |
|
23 |
| - private static readonly Type ENTITY_BASE = typeof(Entity); |
| 23 | + private static readonly Type ENTITY_BASE = typeof(Entity); |
24 | 24 |
|
25 |
| - //------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 25 | + //------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
26 | 26 |
|
27 | 27 |
|
28 |
| - private static void AppendEnum( Type type, StringBuilder sbPUML ) |
| 28 | + private static void AppendEnum( Type type, StringBuilder sbPUML ) |
| 29 | + { |
| 30 | + sbPUML.AppendLine(); |
| 31 | + sbPUML.AppendLine($"enum {type.Name} {{"); |
| 32 | + |
| 33 | + foreach( object value in Enum.GetValues(type) ) |
29 | 34 | {
|
30 |
| - sbPUML.AppendLine(); |
31 |
| - sbPUML.AppendLine($"enum {type.Name} {{"); |
| 35 | + sbPUML.AppendLine($" {value}"); |
| 36 | + } |
32 | 37 |
|
33 |
| - foreach( object value in Enum.GetValues(type) ) |
34 |
| - { |
35 |
| - sbPUML.AppendLine($" {value}"); |
36 |
| - } |
| 38 | + sbPUML.AppendLine("}"); |
| 39 | + sbPUML.AppendLine(); |
| 40 | + } |
37 | 41 |
|
38 |
| - sbPUML.AppendLine("}"); |
39 |
| - sbPUML.AppendLine(); |
40 |
| - } |
41 | 42 |
|
| 43 | + private static void GenerateUmlDiagramm( Type type, StringBuilder sb ) |
| 44 | + { |
| 45 | + string strOutputDirectory = $"{OUTPUTDIRECTORY}\\{type.Namespace}"; |
| 46 | + string strDiagrammFilenamePng = $"{type.Name}.png"; |
| 47 | + string strDiagrammFilenamePuml = $"{type.Name}.puml"; |
42 | 48 |
|
43 |
| - private static void GenerateUmlDiagramm( Type type, StringBuilder sb ) |
44 |
| - { |
45 |
| - string strOutputDirectory = $"{OUTPUTDIRECTORY}\\{type.Namespace}"; |
46 |
| - string strDiagrammFilenamePng = $"{type.Name}.png"; |
47 |
| - string strDiagrammFilenamePuml = $"{type.Name}.puml"; |
| 49 | + //--------------------------------------------------------------------------------------------------------- |
48 | 50 |
|
49 |
| - //--------------------------------------------------------------------------------------------------------- |
| 51 | + sb.AppendLine(); |
| 52 | + sb.AppendLine($""); |
50 | 53 |
|
51 |
| - sb.AppendLine(); |
52 |
| - sb.AppendLine($""); |
| 54 | + //--------------------------------------------------------------------------------------------------------- |
53 | 55 |
|
54 |
| - //--------------------------------------------------------------------------------------------------------- |
| 56 | + StringBuilder sbPUML = new(8192); |
55 | 57 |
|
56 |
| - StringBuilder sbPUML = new(8192); |
| 58 | + sbPUML.AppendLine("@startuml"); |
| 59 | + sbPUML.AppendLine("hide empty members"); |
| 60 | + sbPUML.AppendLine("skinparam monochrome true"); |
| 61 | + sbPUML.AppendLine("skinparam backgroundcolor transparent"); |
57 | 62 |
|
58 |
| - sbPUML.AppendLine("@startuml"); |
59 |
| - sbPUML.AppendLine("hide empty members"); |
60 |
| - sbPUML.AppendLine("skinparam monochrome true"); |
61 |
| - sbPUML.AppendLine("skinparam backgroundcolor transparent"); |
| 63 | + //--------------------------------------------- |
62 | 64 |
|
63 |
| - //--------------------------------------------- |
| 65 | + AppendEnum(type, sbPUML); |
64 | 66 |
|
65 |
| - AppendEnum(type, sbPUML); |
| 67 | + //--------------------------------------------- |
66 | 68 |
|
67 |
| - //--------------------------------------------- |
| 69 | + sbPUML.AppendLine("@enduml"); |
68 | 70 |
|
69 |
| - sbPUML.AppendLine("@enduml"); |
| 71 | + //--------------------------------------------------------------------------------------------------------- |
70 | 72 |
|
71 |
| - //--------------------------------------------------------------------------------------------------------- |
| 73 | + string strOutputFilename = $"{strOutputDirectory}\\{strDiagrammFilenamePuml}"; |
| 74 | + File.WriteAllTextAsync(strOutputFilename, sbPUML.ToString(), Encoding.UTF8); |
| 75 | + GeneratorTool.PlantUml(strOutputFilename); |
| 76 | + } |
72 | 77 |
|
73 |
| - string strOutputFilename = $"{strOutputDirectory}\\{strDiagrammFilenamePuml}"; |
74 |
| - File.WriteAllTextAsync(strOutputFilename, sbPUML.ToString(), Encoding.UTF8); |
75 |
| - GeneratorTool.PlantUml(strOutputFilename); |
76 |
| - } |
| 78 | + //------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
77 | 79 |
|
78 |
| - //------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
79 | 80 |
|
| 81 | + private static void GenerateEnumerationFile( Type type ) |
| 82 | + { |
| 83 | + string strOutputDirectory = $"{OUTPUTDIRECTORY}\\{type.Namespace}"; |
80 | 84 |
|
81 |
| - private static void GenerateEnumerationFile( Type type ) |
| 85 | + if( Directory.Exists(strOutputDirectory) == false ) |
82 | 86 | {
|
83 |
| - string strOutputDirectory = $"{OUTPUTDIRECTORY}\\{type.Namespace}"; |
| 87 | + Directory.CreateDirectory(strOutputDirectory); |
| 88 | + } |
84 | 89 |
|
85 |
| - if( Directory.Exists(strOutputDirectory) == false ) |
86 |
| - { |
87 |
| - Directory.CreateDirectory(strOutputDirectory); |
88 |
| - } |
| 90 | + //--------------------------------------------------------------------------------------------------------- |
89 | 91 |
|
90 |
| - //--------------------------------------------------------------------------------------------------------- |
| 92 | + Out.WriteLineAsync($"Create markdown for: {type.FullName}"); |
91 | 93 |
|
92 |
| - Out.WriteLineAsync($"Create markdown for: {type.FullName}"); |
| 94 | + StringBuilder sb = new(8192); |
93 | 95 |
|
94 |
| - StringBuilder sb = new(8192); |
| 96 | + sb.AppendLine($"# {type.Name}"); |
| 97 | + sb.AppendLine(); |
95 | 98 |
|
96 |
| - sb.AppendLine($"# {type.Name}"); |
97 |
| - sb.AppendLine(); |
| 99 | + sb.AppendLine($"## Diagram"); |
| 100 | + GenerateUmlDiagramm(type, sb); |
98 | 101 |
|
99 |
| - sb.AppendLine($"## Diagram"); |
100 |
| - GenerateUmlDiagramm(type, sb); |
| 102 | + //--------------------------------------------------------------------------------------------------------- |
101 | 103 |
|
102 |
| - //--------------------------------------------------------------------------------------------------------- |
| 104 | + sb.AppendLine(); |
| 105 | + sb.AppendLine("<hr style=\"background: blue;\" />"); |
103 | 106 |
|
104 |
| - sb.AppendLine(); |
105 |
| - sb.AppendLine("<hr style=\"background: blue;\" />"); |
| 107 | + File.WriteAllTextAsync($"{strOutputDirectory}\\{type.Name}.md", sb.ToString(), Encoding.UTF8); |
| 108 | + } |
106 | 109 |
|
107 |
| - File.WriteAllTextAsync($"{strOutputDirectory}\\{type.Name}.md", sb.ToString(), Encoding.UTF8); |
108 |
| - } |
109 | 110 |
|
| 111 | + private static void GenerateEnumerationOverviewFile( List<Type> enumerations ) |
| 112 | + { |
| 113 | + StringBuilder sb = new(8192); |
| 114 | + sb.AppendLine("# Enumerations Overview"); |
110 | 115 |
|
111 |
| - private static void GenerateEnumerationOverviewFile( List<Type> enumerations ) |
| 116 | + foreach( IGrouping<string, Type> enumerationgroup in from enumeration in enumerations group enumeration by enumeration.Namespace into ng orderby ng.Key select ng ) |
112 | 117 | {
|
113 |
| - StringBuilder sb = new(8192); |
114 |
| - sb.AppendLine("# Enumerations Overview"); |
| 118 | + sb.AppendLine(""); |
| 119 | + sb.AppendLine(""); |
| 120 | + sb.AppendLine($"## `{enumerationgroup.Key}`"); |
| 121 | + sb.AppendLine(""); |
115 | 122 |
|
116 |
| - foreach( IGrouping<string, Type> enumerationgroup in from enumeration in enumerations group enumeration by enumeration.Namespace into ng orderby ng.Key select ng ) |
117 |
| - { |
118 |
| - sb.AppendLine(""); |
119 |
| - sb.AppendLine(""); |
120 |
| - sb.AppendLine($"## `{enumerationgroup.Key}`"); |
121 |
| - sb.AppendLine(""); |
| 123 | + sb.AppendLine("|Enumeration|Description|Values|"); |
| 124 | + sb.AppendLine("|:----------|:----------|:-----|"); |
122 | 125 |
|
123 |
| - sb.AppendLine("|Enumeration|Description|Values|"); |
124 |
| - sb.AppendLine("|:----------|:----------|:-----|"); |
| 126 | + string strPath = enumerationgroup.Key [11..].Replace('.', '/'); |
125 | 127 |
|
126 |
| - string strPath = enumerationgroup.Key [11..].Replace('.', '/'); |
| 128 | + foreach( Type enumeration in from type in enumerationgroup orderby type.Name select type ) |
| 129 | + { |
| 130 | + DescriptionAttribute da = (DescriptionAttribute) enumeration.GetCustomAttribute(typeof(DescriptionAttribute)); |
127 | 131 |
|
128 |
| - foreach( Type enumeration in from type in enumerationgroup orderby type.Name select type ) |
| 132 | + if( da == null ) |
129 | 133 | {
|
130 |
| - DescriptionAttribute da = (DescriptionAttribute) enumeration.GetCustomAttribute(typeof(DescriptionAttribute)); |
131 |
| - |
132 |
| - if( da == null ) |
133 |
| - { |
134 |
| - throw new Exception($"{enumeration.FullName} have no description!"); |
135 |
| - } |
| 134 | + throw new Exception($"{enumeration.FullName} have no description!"); |
| 135 | + } |
136 | 136 |
|
137 |
| - da.Validate(enumeration); |
| 137 | + da.Validate(enumeration); |
138 | 138 |
|
139 |
| - string strLinkToMarkdown = $"[{enumeration.Name}](./{enumerationgroup.Key}/{enumeration.Name}.md)"; |
| 139 | + string strLinkToMarkdown = $"[{enumeration.Name}](./{enumerationgroup.Key}/{enumeration.Name}.md)"; |
140 | 140 |
|
141 |
| - sb.AppendLine($"|{strLinkToMarkdown}|{da.Description}|{Enum.GetNames(enumeration).ToFlatString()}|"); |
142 |
| - } |
| 141 | + sb.AppendLine($"|{strLinkToMarkdown}|{da.Description}|{Enum.GetNames(enumeration).ToFlatString()}|"); |
143 | 142 | }
|
| 143 | + } |
144 | 144 |
|
145 |
| - sb.AppendLine(); |
146 |
| - sb.AppendLine("<hr style=\"background: blue;\" />"); |
| 145 | + sb.AppendLine(); |
| 146 | + sb.AppendLine("<hr style=\"background: blue;\" />"); |
147 | 147 |
|
148 |
| - File.WriteAllTextAsync($"{OUTPUTDIRECTORY}\\README.md", sb.ToString(), Encoding.UTF8); |
149 |
| - } |
| 148 | + File.WriteAllTextAsync($"{OUTPUTDIRECTORY}\\README.md", sb.ToString(), Encoding.UTF8); |
| 149 | + } |
150 | 150 |
|
151 |
| - //------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 151 | + //------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
152 | 152 |
|
153 | 153 |
|
154 |
| - public static void Generate() |
155 |
| - { |
156 |
| - Assembly assembly = ENTITY_BASE.Assembly; |
| 154 | + public static void Generate() |
| 155 | + { |
| 156 | + Assembly assembly = ENTITY_BASE.Assembly; |
157 | 157 |
|
158 |
| - Out.WriteLineAsync(); |
159 |
| - Out.WriteLineAsync($"{assembly.FullName}"); |
| 158 | + Out.WriteLineAsync(); |
| 159 | + Out.WriteLineAsync($"{assembly.FullName}"); |
160 | 160 |
|
161 |
| - new DirectoryInfo(OUTPUTDIRECTORY).DeleteDirectoryContentRecursiv(ex => Error.WriteLineAsync(ex.Message)); |
| 161 | + new DirectoryInfo(OUTPUTDIRECTORY).DeleteDirectoryContentRecursiv(ex => Error.WriteLineAsync(ex.Message)); |
162 | 162 |
|
163 |
| - //--------------------------------------------------------------------------------------------------------- |
| 163 | + //--------------------------------------------------------------------------------------------------------- |
164 | 164 |
|
165 |
| - List<Type> enumerations = new(); |
| 165 | + List<Type> enumerations = new(); |
166 | 166 |
|
167 |
| - foreach( Type type in assembly.ExportedTypes ) |
| 167 | + foreach( Type type in assembly.ExportedTypes ) |
| 168 | + { |
| 169 | + if( type.IsEnum == false ) |
168 | 170 | {
|
169 |
| - if( type.IsEnum == false ) |
170 |
| - { |
171 |
| - continue; |
172 |
| - } |
173 |
| - enumerations.Add(type); |
| 171 | + continue; |
174 | 172 | }
|
| 173 | + enumerations.Add(type); |
| 174 | + } |
175 | 175 |
|
176 |
| - //--------------------------------------------------------------------------------------------------------- |
| 176 | + //--------------------------------------------------------------------------------------------------------- |
177 | 177 |
|
178 |
| - enumerations.ForEach(enumeration => GenerateEnumerationFile(enumeration)); |
| 178 | + enumerations.ForEach(enumeration => GenerateEnumerationFile(enumeration)); |
179 | 179 |
|
180 |
| - GenerateEnumerationOverviewFile(enumerations); |
181 |
| - } |
| 180 | + GenerateEnumerationOverviewFile(enumerations); |
182 | 181 | }
|
183 | 182 | }
|
0 commit comments