-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Doki Extensions concept * consistent member xml documentation * TryGetParent Doki.Extensions * support multiple summaries for member documentation * generate docs
- Loading branch information
1 parent
5010f7b
commit e44ef2e
Showing
15 changed files
with
364 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
...oki.Extensions/Doki.Extensions/Doki.Extensions.DocumentationObjectExtensions.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
[Packages](../../README.md) / [Doki.Extensions](../README.md) / [Doki.Extensions](README.md) / | ||
|
||
# DocumentationObjectExtensions Class | ||
|
||
## Definition | ||
|
||
Namespace: [Doki.Extensions](README.md) | ||
|
||
Assembly: [Doki.Extensions.dll](../README.md) | ||
|
||
Package: [Doki.Extensions](https://www.nuget.org/packages/Doki.Extensions) | ||
|
||
--- | ||
|
||
```csharp | ||
public static class DocumentationObjectExtensions | ||
``` | ||
|
||
Inheritance: [System.Object](https://learn.microsoft.com/en-us/dotnet/api/System.Object) → DocumentationObjectExtensions | ||
|
||
## Methods | ||
|
||
| |Summary| | ||
|---|---| | ||
|TryGetParent(Doki.DocumentationRoot, Doki.DocumentationObject)|| | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Doki.Extensions Namespace | ||
|
||
## Types | ||
|
||
- [DocumentationObjectExtensions](Doki.Extensions.DocumentationObjectExtensions.md) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Doki.Extensions | ||
|
||
Provides extensions for Doki documentation generation | ||
|
||
## Namespaces | ||
|
||
- [Doki.Extensions](Doki.Extensions/README.md) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
namespace Doki.Extensions; | ||
|
||
public static class DocumentationObjectExtensions | ||
{ | ||
public static DocumentationObject? TryGetParent(this DocumentationRoot root, DocumentationObject child) | ||
{ | ||
ArgumentNullException.ThrowIfNull(root); | ||
ArgumentNullException.ThrowIfNull(child); | ||
|
||
return child.Parent ?? SearchParent(root, child); | ||
} | ||
|
||
private static DocumentationObject? SearchParent(DocumentationObject from, DocumentationObject to) | ||
{ | ||
if (from == to) return from; | ||
|
||
switch (from) | ||
{ | ||
case DocumentationRoot root: return SearchParentIn(root.Assemblies, to); | ||
case AssemblyDocumentation assemblyDocumentation: | ||
return SearchParentIn(assemblyDocumentation.Namespaces, to); | ||
case NamespaceDocumentation namespaceDocumentation: return SearchParentIn(namespaceDocumentation.Types, to); | ||
case TypeDocumentation typeDocumentation: | ||
{ | ||
var constructor = SearchParentIn(typeDocumentation.Constructors, to); | ||
if (constructor != null) return constructor; | ||
|
||
var method = SearchParentIn(typeDocumentation.Methods, to); | ||
if (method != null) return method; | ||
|
||
var property = SearchParentIn(typeDocumentation.Properties, to); | ||
if (property != null) return property; | ||
|
||
var field = SearchParentIn(typeDocumentation.Fields, to); | ||
if (field != null) return field; | ||
|
||
var interfaceDocumentation = SearchParentIn(typeDocumentation.Interfaces, to); | ||
if (interfaceDocumentation != null) return interfaceDocumentation; | ||
|
||
var derivedType = SearchParentIn(typeDocumentation.DerivedTypes, to); | ||
if (derivedType != null) return derivedType; | ||
|
||
var result = SearchParentInTypeDocumentationReference(typeDocumentation, to); | ||
if (result != null) return result; | ||
|
||
break; | ||
} | ||
case GenericTypeArgumentDocumentation genericTypeArgumentDocumentation: | ||
{ | ||
if (genericTypeArgumentDocumentation.Description != null) | ||
{ | ||
var description = SearchParent(genericTypeArgumentDocumentation.Description, to); | ||
if (description != null) return description; | ||
} | ||
|
||
var result = SearchParentInTypeDocumentationReference(genericTypeArgumentDocumentation, to); | ||
if (result != null) return result; | ||
|
||
break; | ||
} | ||
case TypeDocumentationReference typeDocumentationReference: | ||
{ | ||
var result = SearchParentInTypeDocumentationReference(typeDocumentationReference, to); | ||
if (result != null) return result; | ||
|
||
break; | ||
} | ||
case MemberDocumentation memberDocumentation: | ||
{ | ||
var result = SearchParentInMemberDocumentation(memberDocumentation, to); | ||
if (result != null) return result; | ||
|
||
break; | ||
} | ||
case XmlDocumentation xmlDocumentation: | ||
{ | ||
var result = SearchParentIn(xmlDocumentation.Contents, to); | ||
if (result != null) return result; | ||
|
||
break; | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
private static DocumentationObject? SearchParentInTypeDocumentationReference( | ||
TypeDocumentationReference typeDocumentationReference, DocumentationObject to) | ||
{ | ||
if (typeDocumentationReference.BaseType != null) | ||
{ | ||
var baseType = SearchParent(typeDocumentationReference.BaseType, to); | ||
if (baseType != null) return baseType; | ||
} | ||
|
||
var genericArgument = SearchParentIn(typeDocumentationReference.GenericArguments, to); | ||
return genericArgument ?? SearchParentInMemberDocumentation(typeDocumentationReference, to); | ||
} | ||
|
||
private static DocumentationObject? SearchParentInMemberDocumentation(MemberDocumentation memberDocumentation, | ||
DocumentationObject to) | ||
{ | ||
var summary = SearchParentIn(memberDocumentation.Summaries, to); | ||
if (summary != null) return summary; | ||
|
||
var remarks = SearchParentIn(memberDocumentation.Remarks, to); | ||
if (remarks != null) return remarks; | ||
|
||
var example = SearchParentIn(memberDocumentation.Examples, to); | ||
return example; | ||
} | ||
|
||
private static DocumentationObject? SearchParentIn(IEnumerable<DocumentationObject> children, | ||
DocumentationObject to) | ||
{ | ||
return children.Select(child => SearchParent(child, to)).OfType<DocumentationObject>().FirstOrDefault(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<PackageId>Doki.Extensions</PackageId> | ||
<Authors>david@vollmers.org</Authors> | ||
<Copyright>David Vollmers</Copyright> | ||
<Description>Provides extensions for Doki documentation generation</Description> | ||
<PackageProjectUrl>https://github.com/DavidVollmers/doki</PackageProjectUrl> | ||
<PackageLicenseExpression>MIT</PackageLicenseExpression> | ||
<PackageReadmeFile>README.md</PackageReadmeFile> | ||
<PackageIcon>logo-64x64.png</PackageIcon> | ||
<RepositoryType>git</RepositoryType> | ||
<RepositoryUrl>https://github.com/DavidVollmers/doki.git</RepositoryUrl> | ||
<TargetFrameworks>net7.0;net8.0</TargetFrameworks> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<PackageOutputPath>..\..\nuget</PackageOutputPath> | ||
<LangVersion>latest</LangVersion> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<None Include="..\..\README.md" Pack="true" PackagePath="\"/> | ||
<None Include="..\..\LICENSE.txt" Pack="true" PackagePath="\"/> | ||
<None Include="..\..\assets\logo-64x64.png" Pack="true" PackagePath="\"/> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Doki.Abstractions\Doki.Abstractions.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Oops, something went wrong.