Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 34 additions & 11 deletions src/Docfx.Dotnet/ManagedReference/Resolvers/SetDerivedClass.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Runtime.InteropServices;
using Docfx.DataContracts.ManagedReference;

namespace Docfx.Dotnet;
Expand All @@ -22,6 +23,7 @@ private void UpdateDerivedClassMapping(List<MetadataItem> items, Dictionary<stri
{
foreach (var item in items ?? Enumerable.Empty<MetadataItem>())
{
// Handle class inheritance
var inheritance = item.Inheritance;
if (inheritance is { Count: > 0 })
{
Expand All @@ -35,14 +37,32 @@ private void UpdateDerivedClassMapping(List<MetadataItem> items, Dictionary<stri
// ignore System.Object's derived class
if (superClass != "System.Object")
{
if (_derivedClassMapping.TryGetValue(superClass, out List<string> derivedClasses))
{
ref var derivedClasses = ref CollectionsMarshal.GetValueRefOrAddDefault(_derivedClassMapping, superClass, out var exists);
if (exists)
derivedClasses.Add(item.Name);
}
else
derivedClasses = [item.Name];
}
}

// Handle interface implementations
var implements = item.Implements;
if (implements is { Count: > 0 })
{
foreach (var implementedInterface in implements)
{
var superClass = implementedInterface;

if (reference.TryGetValue(superClass, out var referenceItem))
{
_derivedClassMapping.Add(superClass, [item.Name]);
superClass = referenceItem.Definition ?? superClass;
}

ref var derivedClasses = ref CollectionsMarshal.GetValueRefOrAddDefault(_derivedClassMapping, superClass, out var exists);
if (exists)
derivedClasses.Add(item.Name);
else
derivedClasses = [item.Name];
}
}
}
Expand All @@ -52,13 +72,16 @@ private void AppendDerivedClass(List<MetadataItem> items)
{
foreach (var item in items ?? Enumerable.Empty<MetadataItem>())
{
if (item.Type == MemberType.Class)
switch (item.Type)
{
if (_derivedClassMapping.TryGetValue(item.Name, out List<string> derivedClasses))
{
derivedClasses.Sort();
item.DerivedClasses = derivedClasses;
}
case MemberType.Class:
case MemberType.Interface:
if (_derivedClassMapping.TryGetValue(item.Name, out List<string> derivedClasses))
{
derivedClasses.Sort();
item.DerivedClasses = derivedClasses;
}
continue;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,24 @@
}
]
},
"derivedClasses": [
{
"isEii": false,
"isExtensionMethod": false,
"specName": [
{
"lang": "csharp",
"value": "<xref uid=\"CSharp11.StaticAbstractMembersInInterfaces.RepeatSequence\" displayProperty=\"name\"/>"
},
{
"lang": "vb",
"value": "<xref uid=\"CSharp11.StaticAbstractMembersInInterfaces.RepeatSequence\" displayProperty=\"name\"/>"
}
],
"level": 0,
"index": 1
}
],
"level": 0,
"_systemKeys": [
"uid",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,24 @@
}
]
},
"derivedClasses": [
{
"isEii": false,
"isExtensionMethod": false,
"specName": [
{
"lang": "csharp",
"value": "<xref uid=\"BuildFromProject.Class1.Issue8948\" displayProperty=\"name\"/>"
},
{
"lang": "vb",
"value": "<xref uid=\"BuildFromProject.Class1.Issue8948\" displayProperty=\"name\"/>"
}
],
"level": 0,
"index": 1
}
],
"level": 0,
"_appName": "Seed",
"_appTitle": "docfx seed website",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,24 @@
}
]
},
"derivedClasses": [
{
"isEii": false,
"isExtensionMethod": false,
"specName": [
{
"lang": "csharp",
"value": "<xref uid=\"BuildFromProject.Inheritdoc.Issue9736.JsonApiOptions\" displayProperty=\"name\"/>"
},
{
"lang": "vb",
"value": "<xref uid=\"BuildFromProject.Inheritdoc.Issue9736.JsonApiOptions\" displayProperty=\"name\"/>"
}
],
"level": 0,
"index": 1
}
],
"level": 0,
"_appName": "Seed",
"_appTitle": "docfx seed website",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1099,6 +1099,24 @@
}
]
},
"derivedClasses": [
{
"isEii": false,
"isExtensionMethod": false,
"specName": [
{
"lang": "csharp",
"value": "<xref uid=\"CatLibrary.Cat`2\" displayProperty=\"name\"/>"
},
{
"lang": "vb",
"value": "<xref uid=\"CatLibrary.Cat`2\" displayProperty=\"name\"/>"
}
],
"level": 0,
"index": 1
}
],
"level": 0,
"conceptual": "<h3 id=\"welcome-to-the-animal-world\" sourcefile=\"specs/CatLibrary.IAnimal.md\" sourcestartlinenumber=\"6\">Welcome to the <strong sourcefile=\"specs/CatLibrary.IAnimal.md\" sourcestartlinenumber=\"6\">Animal</strong> world!</h3>\n",
"_appName": "Seed",
Expand Down