33using System . Text ;
44using DocFxMarkdownGen ;
55using Microsoft . Extensions . Logging ;
6+ using ServiceStack ;
67using YamlDotNet . Serialization ;
78using YamlDotNet . Serialization . NamingConventions ;
89
@@ -249,4 +250,42 @@ void Do(string type, string header)
249250 str . AppendLine ( ) ;
250251 await File . WriteAllTextAsync ( Path . Join ( config . OutputPath , $ "index.md") , str . ToString ( ) ) ;
251252}
252- logger . LogInformation ( $ "Markdown finished in { stopwatch . ElapsedMilliseconds } ms.") ;
253+ logger . LogInformation ( $ "Markdown finished in { stopwatch . ElapsedMilliseconds } ms.") ;
254+
255+ if ( config . OutputStats )
256+ {
257+ var namespaces = items . Values . Count ( x => x . Type == "Namespace" ) ;
258+ var classes = items . Values . Count ( x => x . Type == "Class" ) ;
259+ var structs = items . Values . Count ( x => x . Type == "Struct" ) ;
260+ var interfaces = items . Values . Count ( x => x . Type == "Interface" ) ;
261+ var enums = items . Values . Count ( x => x . Type == "Enum" ) ;
262+
263+ var classesByNamespace = items . Values . Where ( x => x . Type == "Class" )
264+ . GroupBy ( y => y . Parent ) ;
265+
266+ var structsByNamespace = items . Values . Where ( x => x . Type == "Struct" )
267+ . GroupBy ( y => y . Parent ) ;
268+
269+ var enumsByNamespace = items . Values . Where ( x => x . Type == "Enum" )
270+ . GroupBy ( y => y . Parent ) ;
271+
272+ var interfacesByNamespace = items . Values . Where ( x => x . Type == "Interface" )
273+ . GroupBy ( y => y . Parent ) ;
274+
275+ var results = new CodeBaseStats
276+ {
277+ Namespaces = namespaces ,
278+ Classes = classes ,
279+ Structs = structs ,
280+ Interfaces = interfaces ,
281+ Enums = enums ,
282+ ClassesByNamespace = classesByNamespace . ToDictionary ( x => x . Key , y => y . Count ( ) ) ,
283+ StructsByNamespace = structsByNamespace . ToDictionary ( x => x . Key , y => y . Count ( ) ) ,
284+ EnumsByNamespace = enumsByNamespace . ToDictionary ( x => x . Key , y => y . Count ( ) ) ,
285+ InterfacesByNamespace = interfacesByNamespace . ToDictionary ( x => x . Key , y => y . Count ( ) )
286+ } ;
287+
288+ Console . WriteLine ( "Stats: " ) ;
289+ Console . WriteLine ( results . ToJson ( ) ) ;
290+ File . WriteAllText ( "./stats.json" , results . ToJson ( ) ) ;
291+ }
0 commit comments