1
- // Licensed to the .NET Foundation under one or more agreements.
1
+ // Licensed to the .NET Foundation under one or more agreements.
2
2
// The .NET Foundation licenses this file to you under the MIT license.
3
3
4
+ using System . Runtime . InteropServices ;
4
5
using Docfx . DataContracts . ManagedReference ;
5
6
6
7
namespace Docfx . Dotnet ;
@@ -22,6 +23,7 @@ private void UpdateDerivedClassMapping(List<MetadataItem> items, Dictionary<stri
22
23
{
23
24
foreach ( var item in items ?? Enumerable . Empty < MetadataItem > ( ) )
24
25
{
26
+ // Handle class inheritance
25
27
var inheritance = item . Inheritance ;
26
28
if ( inheritance is { Count : > 0 } )
27
29
{
@@ -35,15 +37,30 @@ private void UpdateDerivedClassMapping(List<MetadataItem> items, Dictionary<stri
35
37
// ignore System.Object's derived class
36
38
if ( superClass != "System.Object" )
37
39
{
38
- if ( _derivedClassMapping . TryGetValue ( superClass , out List < string > derivedClasses ) )
39
- {
40
+ ref var derivedClasses = ref CollectionsMarshal . GetValueRefOrAddDefault ( _derivedClassMapping , superClass , out var exists ) ;
41
+ if ( exists )
40
42
derivedClasses . Add ( item . Name ) ;
41
- }
42
43
else
43
- {
44
- _derivedClassMapping . Add ( superClass , [ item . Name ] ) ;
45
- }
44
+ derivedClasses = [ item . Name ] ;
45
+ }
46
+ }
47
+
48
+ // Handle interface implementations
49
+ var implements = item . Implements ;
50
+ if ( implements is { Count : > 0 } )
51
+ {
52
+ var superClass = implements [ implements . Count - 1 ] ;
53
+
54
+ if ( reference . TryGetValue ( superClass , out var referenceItem ) )
55
+ {
56
+ superClass = referenceItem . Definition ?? superClass ;
46
57
}
58
+
59
+ ref var derivedClasses = ref CollectionsMarshal . GetValueRefOrAddDefault ( _derivedClassMapping , superClass , out var exists ) ;
60
+ if ( exists )
61
+ derivedClasses . Add ( item . Name ) ;
62
+ else
63
+ derivedClasses = [ item . Name ] ;
47
64
}
48
65
}
49
66
}
@@ -52,13 +69,16 @@ private void AppendDerivedClass(List<MetadataItem> items)
52
69
{
53
70
foreach ( var item in items ?? Enumerable . Empty < MetadataItem > ( ) )
54
71
{
55
- if ( item . Type == MemberType . Class )
72
+ switch ( item . Type )
56
73
{
57
- if ( _derivedClassMapping . TryGetValue ( item . Name , out List < string > derivedClasses ) )
58
- {
59
- derivedClasses . Sort ( ) ;
60
- item . DerivedClasses = derivedClasses ;
61
- }
74
+ case MemberType . Class :
75
+ case MemberType . Interface :
76
+ if ( _derivedClassMapping . TryGetValue ( item . Name , out List < string > derivedClasses ) )
77
+ {
78
+ derivedClasses . Sort ( ) ;
79
+ item . DerivedClasses = derivedClasses ;
80
+ }
81
+ continue ;
62
82
}
63
83
}
64
84
}
0 commit comments