Skip to content

Commit c006d10

Browse files
committed
refactor: 精简代码
1 parent 22bc849 commit c006d10

File tree

1 file changed

+33
-33
lines changed

1 file changed

+33
-33
lines changed

src/BootstrapBlazor/Utils/Utility.cs

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -434,23 +434,23 @@ public static void CreateDisplayByFieldType(this RenderTreeBuilder builder, IEdi
434434
else
435435
{
436436
builder.OpenComponent(0, typeof(Display<>).MakeGenericType(fieldType));
437-
builder.AddAttribute(10, nameof(Display<string>.DisplayText), displayName);
438-
builder.AddAttribute(20, nameof(Display<string>.Value), fieldValue);
439-
builder.AddAttribute(30, nameof(Display<string>.Lookup), item.Lookup);
440-
builder.AddAttribute(30, nameof(Display<string>.LookupService), item.LookupService);
441-
builder.AddAttribute(40, nameof(Display<string>.LookupServiceKey), item.LookupServiceKey);
442-
builder.AddAttribute(50, nameof(Display<string>.LookupServiceData), item.LookupServiceData);
443-
builder.AddAttribute(60, nameof(Display<string>.LookupStringComparison), item.LookupStringComparison);
444-
builder.AddAttribute(65, nameof(Display<string>.ShowLabelTooltip), item.ShowLabelTooltip);
437+
builder.AddAttribute(10, nameof(Display<>.DisplayText), displayName);
438+
builder.AddAttribute(20, nameof(Display<>.Value), fieldValue);
439+
builder.AddAttribute(30, nameof(Display<>.Lookup), item.Lookup);
440+
builder.AddAttribute(30, nameof(Display<>.LookupService), item.LookupService);
441+
builder.AddAttribute(40, nameof(Display<>.LookupServiceKey), item.LookupServiceKey);
442+
builder.AddAttribute(50, nameof(Display<>.LookupServiceData), item.LookupServiceData);
443+
builder.AddAttribute(60, nameof(Display<>.LookupStringComparison), item.LookupStringComparison);
444+
builder.AddAttribute(65, nameof(Display<>.ShowLabelTooltip), item.ShowLabelTooltip);
445445
if (item is ITableColumn col)
446446
{
447447
if (col.Formatter != null)
448448
{
449-
builder.AddAttribute(70, nameof(Display<string>.FormatterAsync), CacheManager.GetFormatterInvoker(fieldType, col.Formatter));
449+
builder.AddAttribute(70, nameof(Display<>.FormatterAsync), CacheManager.GetFormatterInvoker(fieldType, col.Formatter));
450450
}
451451
else if (!string.IsNullOrEmpty(col.FormatString))
452452
{
453-
builder.AddAttribute(80, nameof(Display<string>.FormatString), col.FormatString);
453+
builder.AddAttribute(80, nameof(Display<>.FormatString), col.FormatString);
454454
}
455455
builder.AddAttribute(90, "class", col.CssClass);
456456
}
@@ -484,31 +484,31 @@ public static void CreateComponentByFieldType(this RenderTreeBuilder builder, Co
484484
builder.OpenComponent(0, componentType);
485485
if (componentType.IsSubclassOf(typeof(ValidateBase<>).MakeGenericType(fieldType)))
486486
{
487-
builder.AddAttribute(10, nameof(ValidateBase<string>.DisplayText), displayName);
488-
builder.AddAttribute(20, nameof(ValidateBase<string>.Value), fieldValue);
489-
builder.AddAttribute(30, nameof(ValidateBase<string>.ValueChanged), fieldValueChanged);
490-
builder.AddAttribute(40, nameof(ValidateBase<string>.ValueExpression), valueExpression);
491-
builder.AddAttribute(41, nameof(ValidateBase<string>.ShowRequired), GetRequired(item, changedType));
492-
builder.AddAttribute(42, nameof(ValidateBase<string>.RequiredErrorMessage), item.RequiredErrorMessage);
487+
builder.AddAttribute(10, nameof(ValidateBase<>.DisplayText), displayName);
488+
builder.AddAttribute(20, nameof(ValidateBase<>.Value), fieldValue);
489+
builder.AddAttribute(30, nameof(ValidateBase<>.ValueChanged), fieldValueChanged);
490+
builder.AddAttribute(40, nameof(ValidateBase<>.ValueExpression), valueExpression);
491+
builder.AddAttribute(41, nameof(ValidateBase<>.ShowRequired), GetRequired(item, changedType));
492+
builder.AddAttribute(42, nameof(ValidateBase<>.RequiredErrorMessage), item.RequiredErrorMessage);
493493

494494
if (!item.CanWrite(model.GetType(), changedType, isSearch))
495495
{
496-
builder.AddAttribute(50, nameof(ValidateBase<string>.IsDisabled), true);
496+
builder.AddAttribute(50, nameof(ValidateBase<>.IsDisabled), true);
497497
}
498498

499499
if (item.ValidateRules != null)
500500
{
501-
builder.AddAttribute(60, nameof(ValidateBase<string>.ValidateRules), item.ValidateRules);
501+
builder.AddAttribute(60, nameof(ValidateBase<>.ValidateRules), item.ValidateRules);
502502
}
503503

504504
if (item.ShowLabelTooltip != null)
505505
{
506-
builder.AddAttribute(70, nameof(ValidateBase<string>.ShowLabelTooltip), item.ShowLabelTooltip);
506+
builder.AddAttribute(70, nameof(ValidateBase<>.ShowLabelTooltip), item.ShowLabelTooltip);
507507
}
508508

509509
if (skipValidate is true)
510510
{
511-
builder.AddAttribute(71, nameof(ValidateBase<string>.SkipValidate), true);
511+
builder.AddAttribute(71, nameof(ValidateBase<>.SkipValidate), true);
512512
}
513513
}
514514

@@ -525,31 +525,31 @@ public static void CreateComponentByFieldType(this RenderTreeBuilder builder, Co
525525

526526
if (IsCheckboxList(fieldType, componentType) && item.Items != null)
527527
{
528-
builder.AddAttribute(90, nameof(CheckboxList<IEnumerable<string>>.Items), item.Items.Clone());
528+
builder.AddAttribute(90, nameof(CheckboxList<>.Items), item.Items.Clone());
529529
}
530530

531531
// Nullable<bool?>
532532
if (item.ComponentType == typeof(Select<bool?>) && fieldType == typeof(bool?) && !item.IsLookup() && item.Items == null)
533533
{
534-
builder.AddAttribute(100, nameof(Select<bool?>.Items), GetNullableBoolItems(model, fieldName));
534+
builder.AddAttribute(100, nameof(Select<>.Items), GetNullableBoolItems(model, fieldName));
535535
}
536536

537537
// Lookup
538538
if (item.IsLookup() && item.Items == null)
539539
{
540-
builder.AddAttribute(110, nameof(Select<SelectedItem>.ShowSearch), item.ShowSearchWhenSelect);
541-
builder.AddAttribute(115, nameof(Select<SelectedItem>.Items), item.Lookup);
542-
builder.AddAttribute(120, nameof(Select<SelectedItem>.LookupService), lookupService);
543-
builder.AddAttribute(121, nameof(Select<SelectedItem>.LookupServiceKey), item.LookupServiceKey);
544-
builder.AddAttribute(122, nameof(Select<SelectedItem>.LookupServiceData), item.LookupServiceData);
545-
builder.AddAttribute(130, nameof(Select<SelectedItem>.StringComparison), item.LookupStringComparison);
540+
builder.AddAttribute(110, nameof(Select<>.ShowSearch), item.ShowSearchWhenSelect);
541+
builder.AddAttribute(115, nameof(Select<>.Items), item.Lookup);
542+
builder.AddAttribute(120, nameof(Select<>.LookupService), lookupService);
543+
builder.AddAttribute(121, nameof(Select<>.LookupServiceKey), item.LookupServiceKey);
544+
builder.AddAttribute(122, nameof(Select<>.LookupServiceData), item.LookupServiceData);
545+
builder.AddAttribute(130, nameof(Select<>.StringComparison), item.LookupStringComparison);
546546
}
547547

548548
// 增加非枚举类,手动设定 ComponentType 为 Select 并且 Items 有值 自动生成下拉框
549549
if (item.Items != null && item.ComponentType == typeof(Select<>).MakeGenericType(fieldType))
550550
{
551-
builder.AddAttribute(140, nameof(Select<SelectedItem>.Items), item.Items.Clone());
552-
builder.AddAttribute(150, nameof(Select<SelectedItem>.ShowSearch), item.ShowSearchWhenSelect);
551+
builder.AddAttribute(140, nameof(Select<>.Items), item.Items.Clone());
552+
builder.AddAttribute(150, nameof(Select<>.ShowSearch), item.ShowSearchWhenSelect);
553553
}
554554

555555
// 设置 SkipValidate 参数
@@ -563,9 +563,9 @@ public static void CreateComponentByFieldType(this RenderTreeBuilder builder, Co
563563
builder.AddMultipleAttributes(180, item.ComponentParameters);
564564

565565
// 设置 IsPopover
566-
if (componentType.GetPropertyByName(nameof(Select<string>.IsPopover)) != null)
566+
if (componentType.GetPropertyByName(nameof(Select<>.IsPopover)) != null)
567567
{
568-
builder.AddAttribute(190, nameof(Select<string>.IsPopover), item.IsPopover);
568+
builder.AddAttribute(190, nameof(Select<>.IsPopover), item.IsPopover);
569569
}
570570
builder.CloseComponent();
571571
}
@@ -825,7 +825,7 @@ public static string Format(object? source, IFormatProvider provider)
825825
var instance = Activator.CreateInstance(typeof(List<>).MakeGenericType(t));
826826
if (instance != null)
827827
{
828-
var mi = instance.GetType().GetMethod(nameof(List<string>.AddRange));
828+
var mi = instance.GetType().GetMethod(nameof(List<>.AddRange));
829829
if (mi != null)
830830
{
831831
mi.Invoke(instance, [value]);

0 commit comments

Comments
 (0)