Skip to content

Commit

Permalink
adds recursive search for member description (#2735)
Browse files Browse the repository at this point in the history
  • Loading branch information
oneolddev authored Sep 30, 2024
1 parent d819a17 commit 6ab8a2b
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions examples/Demo/Shared/Components/ApiDocumentation.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ private IEnumerable<MemberDescription> GetMembers(MemberTypes type)
Type = propertyInfo.ToTypeNameString(),
EnumValues = GetEnumValues(propertyInfo),
Default = defaultVaue,
Description = CodeComments.GetSummary(Component.Name + "." + propertyInfo.Name) ?? CodeComments.GetSummary(Component.BaseType?.Name + "." + propertyInfo.Name),
Description = GetMembersDescription(Component, propertyInfo),
IsParameter = isParameter,
Icon = icon
});
Expand All @@ -156,7 +156,7 @@ private IEnumerable<MemberDescription> GetMembers(MemberTypes type)
MemberType = MemberTypes.Event,
Name = propertyInfo.Name,
Type = propertyInfo.ToTypeNameString(),
Description = CodeComments.GetSummary(Component.Name + "." + propertyInfo.Name) ?? CodeComments.GetSummary(Component.BaseType?.Name + "." + propertyInfo.Name)
Description = GetMembersDescription(Component, propertyInfo)
});
}
}
Expand All @@ -176,7 +176,7 @@ private IEnumerable<MemberDescription> GetMembers(MemberTypes type)
Name = methodInfo.Name + genericArguments,
Parameters = methodInfo.GetParameters().Select(i => $"{i.ToTypeNameString()} {i.Name}").ToArray(),
Type = methodInfo.ToTypeNameString(),
Description = CodeComments.GetSummary(Component.Name + "." + methodInfo.Name) ?? CodeComments.GetSummary(Component.BaseType?.Name + "." + methodInfo.Name)
Description = GetMembersDescription(Component, methodInfo)
});
}
}
Expand All @@ -194,6 +194,25 @@ private IEnumerable<MemberDescription> GetMembers(MemberTypes type)
return _allMembers.Where(i => i.MemberType == type);
}

/// <summary>
/// Gets member description. If none provided, base member description is returned.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="component"></param>
/// <param name="memberInfo"></param>
/// <returns>member description</returns>
private static string GetMembersDescription<T>(Type component, T memberInfo) where T : MemberInfo
{
var description = CodeComments.GetSummary(component.Name + "." + memberInfo.Name);

if (description == null && component.BaseType != null)
{
description = GetMembersDescription(component.BaseType, memberInfo);
}

return description ?? string.Empty;
}

private static string[] GetEnumValues(PropertyInfo? propertyInfo)
{
if (propertyInfo != null)
Expand Down

0 comments on commit 6ab8a2b

Please sign in to comment.