Skip to content

Commit

Permalink
Merge pull request #636 from havit/feature/ComponentApiDoc_GenericTyp…
Browse files Browse the repository at this point in the history
…eLinks

[doc] HxCalendar doc link to HxInputDate leads to non-generic type instead of component #614
  • Loading branch information
hakenr authored Oct 26, 2023
2 parents a235cfc + bb9a23b commit 7bf3464
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion Havit.Blazor.Documentation/Model/MemberModel.cs
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@ public abstract class MemberModel
private Type enclosingType;

private bool generic;
private string genericTypeSuffix;

protected string TryFormatComment(string comment, Type enclosingType = null)
{
@@ -66,6 +67,9 @@ private string PrepareLinkForFullLinkGeneration(string link)
generic = IsGeneric(link); // this information is used later to generate a Microsoft documentation link

Regex regex = new("`\\d");
var match = regex.Match(link);
genericTypeSuffix = match.Value;

return regex.Replace(link, "");
}

@@ -143,7 +147,8 @@ private string GenerateHavitDocumentationLink(string[] splitLink)
}
}

isComponent = ApiTypeHelper.GetType(splitLink[^1])?.IsSubclassOf(typeof(ComponentBase)) ?? false;
string className = GetFullGenericTypeName(splitLink[^1]);
isComponent = ApiTypeHelper.GetType(className)?.IsSubclassOf(typeof(ComponentBase)) ?? false;
}
else if (isProperty)
{
@@ -227,6 +232,17 @@ private bool IsGeneric(string link)
return link.Contains('`');
}

/// <returns>The type name including the <c>`1</c> or <c>`2</c> suffix if the type is generic.</returns>
private string GetFullGenericTypeName(string typeName)
{
if (!generic)
{
return typeName;
}

return $"{typeName}{genericTypeSuffix}";
}

private string ConcatenateStringArray(string[] stringArray)
{
StringBuilder sb = new StringBuilder();

0 comments on commit 7bf3464

Please sign in to comment.