@@ -5,6 +5,19 @@ namespace Spectre.Docs.Services;
55
66public class XmlDocumentationService
77{
8+ private static readonly ( string PackageName , string XmlFileName , Type MarkerType ) [ ] _packages =
9+ [
10+ ( "spectre.console" , "Spectre.Console.xml" , typeof ( Console . AnsiConsole ) ) ,
11+ ( "spectre.console.json" , "Spectre.Console.Json.xml" , typeof ( Console . Json . JsonText ) ) ,
12+ ( "spectre.console.imagesharp" , "Spectre.Console.ImageSharp.xml" , typeof ( Console . CanvasImage ) ) ,
13+ ( "spectre.console.cli" , "Spectre.Console.Cli.xml" , typeof ( Console . Cli . CommandApp ) )
14+ ] ;
15+
16+ public static IReadOnlyList < Assembly > Assemblies { get ; } = _packages
17+ . Select ( p => p . MarkerType . Assembly )
18+ . Distinct ( )
19+ . ToArray ( ) ;
20+
821 private readonly Dictionary < string , XmlDocumentation > _documentation = new ( ) ;
922 private bool _isLoaded ;
1023
@@ -15,7 +28,7 @@ public XmlDocumentationService()
1528
1629 public XmlDocumentation ? GetDocumentation ( string memberName )
1730 {
18- return _documentation . TryGetValue ( memberName , out var doc ) ? doc : null ;
31+ return _documentation . GetValueOrDefault ( memberName ) ;
1932 }
2033
2134 public XmlDocumentation ? GetDocumentation ( Type type )
@@ -46,28 +59,29 @@ private void LoadDocumentation()
4659 {
4760 if ( _isLoaded ) return ;
4861
49- try
62+ foreach ( var ( packageName , xmlFileName , markerType ) in _packages )
5063 {
51- var xmlPath = FindXmlDocumentationPath ( ) ;
52- if ( xmlPath == null || ! File . Exists ( xmlPath ) )
64+ try
5365 {
54- // XML documentation file not found - service will return null for all lookups
55- return ;
66+ var xmlPath = FindXmlDocumentationPath ( packageName , xmlFileName , markerType ) ;
67+ if ( xmlPath != null && File . Exists ( xmlPath ) )
68+ {
69+ ParseXmlDocumentation ( xmlPath ) ;
70+ }
71+ }
72+ catch ( Exception )
73+ {
74+ // Error loading XML documentation for this package - continue with next
5675 }
57-
58- ParseXmlDocumentation ( xmlPath ) ;
59- _isLoaded = true ;
60- }
61- catch ( Exception )
62- {
63- // Error loading XML documentation - service will return null for all lookups
6476 }
77+
78+ _isLoaded = true ;
6579 }
6680
67- private string ? FindXmlDocumentationPath ( )
81+ private string ? FindXmlDocumentationPath ( string packageName , string xmlFileName , Type markerType )
6882 {
6983 // Strategy 1: Check assembly location (works when XML is copied to output)
70- var assembly = typeof ( Spectre . Console . AnsiConsole ) . Assembly ;
84+ var assembly = markerType . Assembly ;
7185 var assemblyPath = assembly . Location ;
7286
7387 if ( ! string . IsNullOrEmpty ( assemblyPath ) )
@@ -80,7 +94,7 @@ private void LoadDocumentation()
8094 }
8195
8296 // Strategy 2: Search NuGet global packages folder
83- var nugetPath = FindInNuGetCache ( ) ;
97+ var nugetPath = FindInNuGetCache ( packageName , xmlFileName ) ;
8498 if ( nugetPath != null && File . Exists ( nugetPath ) )
8599 {
86100 return nugetPath ;
@@ -89,11 +103,11 @@ private void LoadDocumentation()
89103 return null ;
90104 }
91105
92- private string ? FindInNuGetCache ( )
106+ private string ? FindInNuGetCache ( string packageName , string xmlFileName )
93107 {
94108 // Get NuGet global packages folder (cross-platform)
95109 var userProfile = Environment . GetFolderPath ( Environment . SpecialFolder . UserProfile ) ;
96- var nugetFolder = Path . Combine ( userProfile , ".nuget" , "packages" , "spectre.console" ) ;
110+ var nugetFolder = Path . Combine ( userProfile , ".nuget" , "packages" , packageName ) ;
97111
98112 if ( ! Directory . Exists ( nugetFolder ) )
99113 {
@@ -122,7 +136,7 @@ private void LoadDocumentation()
122136
123137 foreach ( var tfmDir in tfmDirs )
124138 {
125- var xmlPath = Path . Combine ( tfmDir , "Spectre.Console.xml" ) ;
139+ var xmlPath = Path . Combine ( tfmDir , xmlFileName ) ;
126140 if ( File . Exists ( xmlPath ) )
127141 {
128142 return xmlPath ;
0 commit comments