Skip to content
This repository was archived by the owner on Jan 22, 2026. It is now read-only.

Commit 9db9e67

Browse files
authored
Fix nested classes corner case (#52)
1 parent bcfce8f commit 9db9e67

1 file changed

Lines changed: 18 additions & 5 deletions

File tree

src/BitzArt.XDoc/Utility/XmlParser.cs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
using System.Reflection;
1+
using System.Collections.Frozen;
2+
using System.Reflection;
23
using System.Xml;
34

45
namespace BitzArt.XDoc;
56

67
internal class XmlParser
78
{
89
private readonly XDoc _source;
9-
private readonly Assembly _assembly;
1010
private readonly XmlDocument _xml;
1111
private readonly Dictionary<Type, TypeDocumentation> _results;
12+
private readonly IDictionary<string, Type> _types;
1213

1314
/// <summary>
1415
/// Parses an XML documentation file and creates a dictionary mapping types to their documentation.
@@ -28,9 +29,16 @@ public static Dictionary<Type, TypeDocumentation> Parse(XDoc source, Assembly as
2829
internal XmlParser(XDoc source, Assembly assembly, XmlDocument xml)
2930
{
3031
_source = source;
31-
_assembly = assembly;
3232
_xml = xml;
3333

34+
_types = assembly
35+
.GetTypes()
36+
.Where(t => !string.IsNullOrWhiteSpace(t.FullName))
37+
.ToFrozenDictionary(
38+
t => t.FullName!.Replace('+', '.'), // Replace nested type '+' with '.'
39+
t => t
40+
);
41+
3442
_results = [];
3543
}
3644

@@ -69,7 +77,7 @@ private void Parse(XmlNode node)
6977

7078
private TypeDocumentation ParseTypeNode(XmlNode node, string name)
7179
{
72-
var type = _assembly.GetType(name)
80+
var type = GetTypeFromAssembly(name)
7381
?? throw new InvalidOperationException($"Type '{name}' not found.");
7482

7583
// We could handle this case by finding and updating the existing object,
@@ -86,6 +94,11 @@ private TypeDocumentation ParseTypeNode(XmlNode node, string name)
8694
return typeDocumentation;
8795
}
8896

97+
private Type? GetTypeFromAssembly(string name)
98+
{
99+
return _types.TryGetValue(name, out var type) ? type : null;
100+
}
101+
89102
private PropertyDocumentation ParsePropertyNode(XmlNode node, string name)
90103
=> ParseMemberNode(name,
91104
(type, memberName, _) => type.GetProperty(memberName),
@@ -181,7 +194,7 @@ private TDocumentation ParseMemberNode<TMember, TDocumentation>(
181194
{
182195
var (typeName, memberName) = XmlMemberNameResolver.ResolveTypeAndMemberName(name);
183196

184-
var type = _assembly.GetType(typeName)
197+
var type = GetTypeFromAssembly(typeName)
185198
?? throw new InvalidOperationException($"Type '{typeName}' not found.");
186199

187200
var parameters = XmlMemberNameResolver.ResolveMethodParameters(name);

0 commit comments

Comments
 (0)