Skip to content

Commit 04e06f2

Browse files
CopilotArgoZhang
andauthored
doc(Comments): support auto generate attribute table component in extensions (#7524)
* Initial plan * Replace AttributeTable Items with Name parameter in all sample files Co-authored-by: ArgoZhang <22001478+ArgoZhang@users.noreply.github.com> * Clean up orphaned XML comments after GetAttributes removal Co-authored-by: ArgoZhang <22001478+ArgoZhang@users.noreply.github.com> * refactor: 移除不使用的私有变量 * refactor: 更改参数为可为空 * refactor: 增加 BootstrapBlazor 注释文档变量 * refactor: 移除默认值 * refactor: 支持扩展组件包参数 * refactor: 临时提交 --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: ArgoZhang <22001478+ArgoZhang@users.noreply.github.com> Co-authored-by: Argo Zhang <argo@live.ca>
1 parent 1eab225 commit 04e06f2

9 files changed

Lines changed: 123 additions & 100 deletions

File tree

src/BootstrapBlazor.Server/Components/Samples/Ajaxs.razor.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,6 @@ class User
6363
private Task Goto() => AjaxService.Goto("/introduction");
6464

6565
private Task GotoSelf() => AjaxService.Goto("/ajax");
66-
67-
/// <summary>
68-
/// 获得属性方法
69-
/// </summary>
70-
/// <returns></returns>
7166
private List<MethodItem> GetMethods() =>
7267
[
7368
new()

src/BootstrapBlazor.Server/Components/Samples/CheckboxLists.razor.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ public partial class CheckboxLists
1818
EnumEducation.Middle, EnumEducation.Primary
1919
};
2020

21-
2221
[NotNull]
2322
private IEnumerable<SelectedItem>? Items1 { get; set; }
2423

src/BootstrapBlazor.Server/Components/Samples/EmbedPdfs.razor.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ public partial class EmbedPdfs
1313
private EmbedPDFTheme _theme = EmbedPDFTheme.System;
1414
private EmbedPDFScrollStrategy _strategy = EmbedPDFScrollStrategy.Vertical;
1515
private string _url = "./samples/sample.pdf";
16-
private string _streamFileName = "";
1716
private string _language = "";
1817

1918
private List<SelectedItem> _languages = new List<SelectedItem>() {

src/BootstrapBlazor.Server/Components/Samples/FlipClocks.razor.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ public partial class FlipClocks
3434

3535
private string CardGroupMarginValueString => $"{CardGroupMarginValue}px";
3636

37-
3837
private bool _isCompleted;
3938
private bool _showYear = false;
4039
private bool _showMonth = false;

src/BootstrapBlazor.Server/Components/Samples/Translators.razor.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,6 @@ private static string FormatResult(TranslationText translation)
4848
var culture = new CultureInfo(translation.TargetLanguage);
4949
return $"{culture.NativeName}: {translation.Text}";
5050
}
51-
52-
/// <summary>
53-
/// 获得属性方法
54-
/// </summary>
55-
/// <returns></returns>
5651
protected MethodItem[] GetMethods() =>
5752
[
5853
new()

src/BootstrapBlazor.Server/Data/AttributeItem.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,32 +13,32 @@ public class AttributeItem
1313
/// <summary>
1414
/// 获得/设置 参数
1515
/// </summary>
16-
public string Name { get; set; } = "";
16+
public string? Name { get; set; }
1717

1818
/// <summary>
1919
/// 获得/设置 说明
2020
/// </summary>
21-
public string Description { get; set; } = "";
21+
public string? Description { get; set; }
2222

2323
/// <summary>
2424
/// 获得/设置 类型
2525
/// </summary>
26-
public string Type { get; set; } = "";
26+
public string? Type { get; set; }
2727

2828
/// <summary>
2929
/// 获得/设置 可选值
3030
/// </summary>
31-
public string ValueList { get; set; } = "";
31+
public string? ValueList { get; set; }
3232

3333
/// <summary>
3434
/// 获得/设置 版本
3535
/// </summary>
36-
public string Version { get; set; } = "10.2.2";
36+
public string? Version { get; set; }
3737

3838
/// <summary>
3939
/// 获得/设置 默认值
4040
/// </summary>
41-
public string DefaultValue { get; set; } = "";
41+
public string? DefaultValue { get; set; }
4242

4343
/// <summary>
4444
/// 获得/设置 是否已弃用

src/BootstrapBlazor.Server/Services/ComponentAttributeCacheService.cs

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ public static class ComponentAttributeCacheService
1818
{
1919
private static readonly ConcurrentDictionary<string, List<AttributeItem>> _cache = new();
2020

21+
private static XDocument? _xmlDoc;
22+
2123
/// <summary>
2224
/// 通过组件类型获取组件的 AttributeItem 列表
2325
/// </summary>
@@ -43,13 +45,21 @@ private static List<AttributeItem> GetAttributeCore(Type type)
4345
.ToArray();
4446
}
4547

46-
var xmlDoc = GetXmlDocumentation(type.Assembly);
48+
// 获得 BootstrapBlazor 程序集 xml 文档
49+
_xmlDoc ??= GetXmlDocumentation(typeof(BootstrapBlazorRoot).Assembly);
50+
XDocument? xmlDoc = null;
51+
if (type.Assembly.GetName().Name != "BootstrapBlazor")
52+
{
53+
// 扩展组件包
54+
xmlDoc = GetXmlDocumentation(type.Assembly);
55+
}
56+
4757
return properties.Select(property => new AttributeItem
4858
{
4959
Name = property.Name,
5060
Type = GetFriendlyTypeName(property.PropertyType),
5161
Description = GetSummary(xmlDoc, property) ?? "",
52-
Version = GetVersion(xmlDoc, property) ?? "10.0.0",
62+
Version = GetVersion(xmlDoc, property),
5363
IsObsolete = property.GetCustomAttribute<ObsoleteAttribute>() != null
5464
}).OrderBy(i => i.Name).ToList();
5565
}
@@ -59,18 +69,19 @@ private static List<AttributeItem> GetAttributeCore(Type type)
5969
/// </summary>
6070
private static string? GetSummary(XDocument? xmlDoc, PropertyInfo property)
6171
{
62-
if (xmlDoc == null) return null;
63-
6472
var type = property.DeclaringType ?? property.PropertyType;
65-
var typeName = type.FullName ?? $"BootstrapBlazor.Components.{type.Name}";
73+
var typeName = $"BootstrapBlazor.Components.{type.Name}";
6674
var memberName = $"P:{typeName}.{property.Name}";
6775
var summaryElement = FindSummaryElement(xmlDoc, memberName);
6876
return summaryElement == null ? null : GetLocalizedSummary(summaryElement);
6977
}
7078

71-
private static XElement? FindSummaryElement(XDocument xmlDoc, string memberName)
79+
private static XElement? FindSummaryElement(XDocument? xmlDoc, string memberName)
7280
{
73-
var memberElement = xmlDoc.Descendants("member")
81+
// 如果 xmlDoc 为空表示为 BootstrapBlazor 组件
82+
var memberElement = xmlDoc?.Descendants("member")
83+
.FirstOrDefault(x => x.Attribute("name")?.Value == memberName)
84+
?? _xmlDoc?.Descendants("member")
7485
.FirstOrDefault(x => x.Attribute("name")?.Value == memberName);
7586

7687
var summaryElement = memberElement?.Element("summary");
@@ -79,8 +90,8 @@ private static List<AttributeItem> GetAttributeCore(Type type)
7990
return null;
8091
}
8192

82-
var doc = summaryElement.Element("inheritdoc")?.Attribute("cref")?.Value;
83-
return doc != null ? FindSummaryElement(xmlDoc, doc) : summaryElement;
93+
var v = summaryElement.Element("inheritdoc")?.Attribute("cref")?.Value;
94+
return v != null ? FindSummaryElement(xmlDoc, v) : summaryElement;
8495
}
8596

8697
private static string? GetLocalizedSummary(XElement? summaryElement)

0 commit comments

Comments
 (0)