-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApiDocsHelper.cs
58 lines (53 loc) · 1.53 KB
/
ApiDocsHelper.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using Statiq.CodeAnalysis;
using System.Text;
namespace TurnerSoftware.Compendium;
public class ApiDocsHelper
{
public static bool HasNonNamespaceChildren(IDocument document)
{
if (document.GetString(CodeAnalysisKeys.SpecificKind) == "Namespace")
{
foreach (var child in document.GetChildren(CodeAnalysisKeys.MemberTypes))
{
if (child.GetString(CodeAnalysisKeys.SpecificKind) != "Namespace")
{
return true;
}
}
return false;
}
return true;
}
public static string GetDisplayName(IDocument document)
{
var apiKind = document.GetString(CodeAnalysisKeys.SpecificKind);
if (apiKind == "Namespace")
{
return $"{document.GetString(CodeAnalysisKeys.QualifiedName)} Namespace";
}
return $"{document.GetString(CodeAnalysisKeys.FullName)} {apiKind}";
}
public static string GetPageTitle(IDocument document)
{
var displayName = GetDisplayName(document);
var specificKind = document.GetString(CodeAnalysisKeys.SpecificKind);
if (specificKind != "Namespace")
{
var containingNamespace = document.GetDocument(CodeAnalysisKeys.ContainingNamespace);
if (containingNamespace is not null)
{
return $"{displayName} ({containingNamespace.GetString(Keys.Title)})";
}
}
return displayName;
}
public static string? GetPackageName(IDocument document)
{
var containingAssembly = document.GetDocument(CodeAnalysisKeys.ContainingAssembly);
if (containingAssembly is not null)
{
return containingAssembly.GetString(CodeAnalysisKeys.DisplayName).RemoveEnd(".dll");
}
return null;
}
}