Skip to content

Commit

Permalink
[doc] Types - Delegate signature does not link to other types #418
Browse files Browse the repository at this point in the history
  • Loading branch information
Harvey1214 committed Nov 29, 2023
1 parent 7fa1aab commit 8e6cc68
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
12 changes: 7 additions & 5 deletions Havit.Blazor.Documentation/Services/ApiRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@ private static readonly (string type, string name)[] typeSimplifications =

public static string FormatType(Type type, bool asLink = true)
{
string typeName = type.ToString(); // e.g. "System.Collections.Generic.List`1[System.String]"
return FormatType(type.ToString(), asLink); // e.g. "System.Collections.Generic.List`1[System.String]"
}

public static string FormatType(string typeName, bool asLink = true)
{
typeName = Regex.Replace(typeName, @"[a-zA-Z]*\.", ""); // Remove namespaces

// simplify known types
Expand Down Expand Up @@ -159,14 +162,13 @@ public static string GenerateLinkForInternalType(string typeName, bool checkForI
typeNameForOwnDocumentation = Regex.Replace(typeNameForOwnDocumentation, "<[a-zA-Z]+>", capture => $"{capture.Value[1..^1]}");
}

if (!checkForInternal)
if (!checkForInternal || ApiTypeHelper.IsLibraryType(typeNameForOwnDocumentation))
{
return GenerateLinkTagForInternalType(typeName, typeNameForOwnDocumentation, linkText, generic);
}

if (ApiTypeHelper.IsLibraryType(typeNameForOwnDocumentation))
else if (ApiTypeHelper.GetType(typeName, true) is not null)
{
return GenerateLinkTagForInternalType(typeName, typeNameForOwnDocumentation, linkText, generic);
return GenerateLinkTagForInternalType(typeName, typeName, linkText, false);
}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,23 @@ private void AdjustDelegate(ComponentApiDocModel model)
Contract.Requires<InvalidOperationException>(model.IsDelegate);

MethodInfo invokeMethodInfo = model.Type.GetMethod("Invoke");
model.DelegateSignature = $"{ApiRenderer.FormatType(invokeMethodInfo.ReturnType, asLink: false)} {ApiRenderer.FormatType(model.Type, asLink: false)}(";
string returnType = string.Empty;

var genericTypeArgument = invokeMethodInfo.ReturnType.GetGenericArguments().FirstOrDefault();

if (genericTypeArgument is not null)
{
string genericTypeArgumentName = genericTypeArgument.ToString();
Console.WriteLine("genericTypeArgument.ToString(): " + genericTypeArgumentName);

returnType = $"Task&lt;{ApiRenderer.FormatType(genericTypeArgumentName, true)}&gt; ";
}
else
{
returnType = ApiRenderer.FormatType(invokeMethodInfo.ReturnType, true);
}

model.DelegateSignature = $"{returnType} {ApiRenderer.FormatType(model.Type, false)} (";
foreach (ParameterInfo param in invokeMethodInfo.GetParameters())
{
model.DelegateSignature += $"{ApiRenderer.FormatType(param.ParameterType)} {param.Name}";
Expand Down

0 comments on commit 8e6cc68

Please sign in to comment.