Skip to content

Commit 870a2b9

Browse files
committed
refactor: 代码规范化
1 parent 73f4ce3 commit 870a2b9

File tree

4 files changed

+24
-14
lines changed

4 files changed

+24
-14
lines changed

src/BootstrapBlazor/Components/Display/Display.razor.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,6 @@ private static string GetTextByValue(IEnumerable<SelectedItem> lookup, TValue va
172172
}));
173173
}
174174

175-
private ILookupService GetLookupService() => LookupService ?? InjectLookupService;
176-
177175
private IEnumerable<SelectedItem>? _lookupData;
178176
private async Task<IEnumerable<SelectedItem>?> GetLookup()
179177
{
@@ -182,7 +180,7 @@ private static string GetTextByValue(IEnumerable<SelectedItem> lookup, TValue va
182180
return Lookup;
183181
}
184182

185-
var lookupService = GetLookupService();
183+
var lookupService = this.GetLookupService(InjectLookupService);
186184
_lookupData ??= await lookupService.GetItemsAsync(LookupServiceKey, LookupServiceData);
187185
return _lookupData;
188186
}

src/BootstrapBlazor/Components/Table/Table.razor.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ private string GetSortTooltip(ITableColumn col) => SortName != col.GetFieldName(
381381

382382
[Inject]
383383
[NotNull]
384-
private ILookupService? LookupService { get; set; }
384+
private ILookupService? InjectLookupService { get; set; }
385385

386386
private bool _breakPointChanged;
387387

@@ -1317,7 +1317,7 @@ RenderFragment RenderTemplate() => col.Template == null
13171317
: col.Template(item);
13181318

13191319
RenderFragment RenderEditTemplate() => col.EditTemplate == null
1320-
? new RenderFragment(builder => builder.CreateComponentByFieldType(this, col, item, changedType, false, col.GetLookupService(LookupService)))
1320+
? new RenderFragment(builder => builder.CreateComponentByFieldType(this, col, item, changedType, false, col.GetLookupService(InjectLookupService)))
13211321
: col.EditTemplate(item);
13221322
}
13231323

@@ -1359,7 +1359,7 @@ void SetDynamicEditTemplate()
13591359
parameters.Add(new(nameof(ValidateBase<string>.OnValueChanged), onValueChanged.Invoke(d, col, (model, column, val) => DynamicContext.OnValueChanged(model, column, val))));
13601360
col.ComponentParameters = parameters;
13611361
}
1362-
builder.CreateComponentByFieldType(this, col, row, changedType, false, col.GetLookupService(LookupService));
1362+
builder.CreateComponentByFieldType(this, col, row, changedType, false, col.GetLookupService(InjectLookupService));
13631363
};
13641364
}
13651365

src/BootstrapBlazor/Extensions/IEditorItemExtensions.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,4 @@ bool ComplexCanWrite()
117117
internal static bool GetIgnore(this IEditorItem col) => col.Ignore ?? false;
118118

119119
internal static bool GetReadonly(this IEditorItem col) => col.Readonly ?? false;
120-
121-
/// <summary>
122-
/// 获得 ILookupService 实例
123-
/// </summary>
124-
/// <param name="item"></param>
125-
/// <param name="service"></param>
126-
/// <returns></returns>
127-
public static ILookupService GetLookupService(this IEditorItem item, ILookupService service) => item.LookupService ?? service;
128120
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the Apache 2.0 License
3+
// See the LICENSE file in the project root for more information.
4+
// Maintainer: Argo Zhang([email protected]) Website: https://www.blazor.zone
5+
6+
namespace BootstrapBlazor.Components;
7+
8+
/// <summary>
9+
/// <see cref="ILookup"/> 扩展方法
10+
/// </summary>
11+
public static class ILooupExtensions
12+
{
13+
/// <summary>
14+
/// 获得 ILookupService 实例
15+
/// </summary>
16+
/// <param name="item"></param>
17+
/// <param name="service"></param>
18+
/// <returns></returns>
19+
public static ILookupService GetLookupService(this ILookup item, ILookupService service) => item.LookupService ?? service;
20+
}

0 commit comments

Comments
 (0)