diff --git a/src/BootstrapBlazor.Server/Data/Foo.cs b/src/BootstrapBlazor.Server/Data/Foo.cs index 8b0988cc851..92ecc5f1c06 100644 --- a/src/BootstrapBlazor.Server/Data/Foo.cs +++ b/src/BootstrapBlazor.Server/Data/Foo.cs @@ -109,7 +109,7 @@ public class Foo /// Generate Foo class, random data /// /// 返回一个Foo类的List,Return a List of Foo class - public static List GenerateFoo(IStringLocalizer localizer, int count = 80) => Enumerable.Range(1, count).Select(i => new Foo() + public static List GenerateFoo(IStringLocalizer localizer, int count = 80) => [.. Enumerable.Range(1, count).Select(i => new Foo() { Id = i, Name = localizer["Foo.Name", $"{i:d4}"], @@ -119,7 +119,7 @@ public class Foo Complete = Random.Shared.Next(1, 100) > 50, Education = Random.Shared.Next(1, 100) > 50 ? EnumEducation.Primary : EnumEducation.Middle, ReadonlyColumn = Random.Shared.Next(10, 50) - }).ToList(); + })]; /// /// 生成 Foo 类 Hobbies 数据 diff --git a/src/BootstrapBlazor/Attributes/AutoGenerateColumnAttribute.cs b/src/BootstrapBlazor/Attributes/AutoGenerateColumnAttribute.cs index 0b806a71dc4..52914a76498 100644 --- a/src/BootstrapBlazor/Attributes/AutoGenerateColumnAttribute.cs +++ b/src/BootstrapBlazor/Attributes/AutoGenerateColumnAttribute.cs @@ -81,20 +81,12 @@ public class AutoGenerateColumnAttribute : AutoGenerateBaseAttribute, ITableColu set => IsVisibleWhenEdit = value ?? true; } - /// - /// - /// - public bool? Required { get; set; } + bool? IEditorItem.Required { get; set; } - /// - /// - /// - public bool? IsRequiredWhenAdd { get; set; } - /// - /// - /// - public bool? IsRequiredWhenEdit { get; set; } + bool? ITableColumn.IsRequiredWhenAdd { get; set; } + + bool? ITableColumn.IsRequiredWhenEdit { get; set; } /// /// @@ -109,7 +101,7 @@ public class AutoGenerateColumnAttribute : AutoGenerateBaseAttribute, ITableColu bool? IEditorItem.ShowLabelTooltip { get => ShowLabelTooltip; - set => ShowLabelTooltip = value.HasValue && value.Value; + set => ShowLabelTooltip = value ?? false; } /// diff --git a/src/BootstrapBlazor/BootstrapBlazor.csproj b/src/BootstrapBlazor/BootstrapBlazor.csproj index 7185b9c967b..7b193de50b5 100644 --- a/src/BootstrapBlazor/BootstrapBlazor.csproj +++ b/src/BootstrapBlazor/BootstrapBlazor.csproj @@ -1,7 +1,7 @@ - 9.3.1-beta26 + 9.3.1-beta27 diff --git a/test/UnitTest/Attributes/AutoGenerateClassTest.cs b/test/UnitTest/Attributes/AutoGenerateClassTest.cs index f77ed200a4d..a9ac8571a79 100644 --- a/test/UnitTest/Attributes/AutoGenerateClassTest.cs +++ b/test/UnitTest/Attributes/AutoGenerateClassTest.cs @@ -70,10 +70,7 @@ public void AutoGenerateColumn_Ok() HeaderTextWrap = true, IsMarkupString = true, - Required = true, - RequiredErrorMessage = "test", - IsRequiredWhenAdd = true, - IsRequiredWhenEdit = true + RequiredErrorMessage = "test" }; Assert.Equal(1, attr.Order); Assert.True(attr.Ignore); @@ -201,6 +198,11 @@ public void AutoGenerateColumn_Ok() attrInterface.ToolboxTemplate = col => builder => builder.AddContent(0, "test"); Assert.NotNull(attrInterface.ToolboxTemplate); + attrInterface.IsRequiredWhenAdd = true; + Assert.True(attrInterface.IsRequiredWhenAdd); + attrInterface.IsRequiredWhenEdit = true; + Assert.True(attrInterface.IsRequiredWhenEdit); + var attrEditor = (IEditorItem)attr; attrEditor.Items = null; Assert.Null(attrEditor.Items); @@ -226,13 +228,13 @@ public void AutoGenerateColumn_Ok() attrEditor.LookupService = new LookupService(); Assert.NotNull(attrEditor.LookupService); + attrEditor.Required = true; + Assert.True(attrEditor.Required); + // 增加 GetDisplay 单元覆盖率 attr.Text = null; Assert.Equal(string.Empty, attr.GetDisplayName()); - Assert.True(attr.Required); - Assert.True(attr.IsRequiredWhenEdit); - Assert.True(attr.IsRequiredWhenAdd); Assert.Equal("test", attr.RequiredErrorMessage); }