Skip to content

Commit

Permalink
TryGetParent Doki.Extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidVollmers committed Jun 22, 2024
1 parent 3361347 commit 54c74cd
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 10 deletions.
55 changes: 46 additions & 9 deletions src/Doki.Extensions/DocumentationObjectExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,49 @@ public static class DocumentationObjectExtensions
var field = SearchParentIn(typeDocumentation.Fields, to);
if (field != null) return field;

var example = SearchParentIn(typeDocumentation.Examples, to);
if (example != null) return example;

var remarks = SearchParentIn(typeDocumentation.Remarks, to);
if (remarks != null) return remarks;

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;
}
}
Expand All @@ -65,12 +96,18 @@ public static class DocumentationObjectExtensions
var genericArgument = SearchParentIn(typeDocumentationReference.GenericArguments, to);
return genericArgument ?? SearchParentInMemberDocumentation(typeDocumentationReference, to);
}

private static DocumentationObject? SearchParentInMemberDocumentation(MemberDocumentation memberDocumentation,
DocumentationObject to)
{
var summary = SearchParentIn(memberDocumentation.Summary, to);
return summary ?? SearchParentIn(memberDocumentation.Remarks, 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,
Expand Down
1 change: 0 additions & 1 deletion src/Doki.Extensions/Doki.Extensions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
<TargetFrameworks>net7.0;net8.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>Doki</RootNamespace>
<PackageOutputPath>..\..\nuget</PackageOutputPath>
<LangVersion>latest</LangVersion>
</PropertyGroup>
Expand Down

0 comments on commit 54c74cd

Please sign in to comment.