From 180b2281578c9eed5cd3598deccd5a1690f0f195 Mon Sep 17 00:00:00 2001 From: Argo-Cloud Date: Mon, 5 Apr 2021 15:28:00 +0800 Subject: [PATCH 1/4] =?UTF-8?q?feat:=20Display=20=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=BC=82=E6=AD=A5=E6=A0=BC=E5=BC=8F=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/Display/Display.razor.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/BootstrapBlazor/Components/Display/Display.razor.cs b/src/BootstrapBlazor/Components/Display/Display.razor.cs index b30e06b6f..cc0b4b56d 100644 --- a/src/BootstrapBlazor/Components/Display/Display.razor.cs +++ b/src/BootstrapBlazor/Components/Display/Display.razor.cs @@ -26,7 +26,7 @@ namespace BootstrapBlazor.Components /// 获得/设置 格式化字符串 /// [Parameter] - public Func? Formatter { get; set; } + public Func>? Formatter { get; set; } /// /// 获得/设置 格式化字符串 如时间类型设置 yyyy-MM-dd @@ -42,7 +42,7 @@ namespace BootstrapBlazor.Components { await base.OnParametersSetAsync(); - CurrentTextAsString = FormatValueAsString(Value); + CurrentTextAsString = await FormatTextAsString(Value); } /// @@ -50,8 +50,8 @@ namespace BootstrapBlazor.Components /// /// /// - protected override string? FormatValueAsString(TValue value) => Formatter != null - ? Formatter.Invoke(value) + protected virtual async Task FormatTextAsString(TValue value) => Formatter != null + ? await Formatter(value) : (!string.IsNullOrEmpty(FormatString) && value != null ? Utility.Format((object)value, FormatString) : FormatText(value)); @@ -70,7 +70,7 @@ namespace BootstrapBlazor.Components { ret = ConvertArrayToString(value); } - else if (value is not string && type.IsAssignableTo(typeof(IEnumerable))) + else if (type.IsGenericType && type.IsAssignableTo(typeof(IEnumerable))) { // 泛型集合 IEnumerable ret = ConvertEnumerableToString(value); -- Gitee From edebdbd7042f82554b1b5221cecfb82182cbe36e Mon Sep 17 00:00:00 2001 From: Argo-Cloud Date: Mon, 5 Apr 2021 15:28:21 +0800 Subject: [PATCH 2/4] =?UTF-8?q?docs:=20=E6=9B=B4=E6=96=B0=E5=BC=82?= =?UTF-8?q?=E6=AD=A5=E6=A0=BC=E5=BC=8F=E5=8C=96=E5=9B=9E=E8=B0=83=E5=A7=94?= =?UTF-8?q?=E6=89=98=E7=A4=BA=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Pages/Samples/Displays.razor.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/BootstrapBlazor.Shared/Pages/Samples/Displays.razor.cs b/src/BootstrapBlazor.Shared/Pages/Samples/Displays.razor.cs index 08eb4f370..292ce4f92 100644 --- a/src/BootstrapBlazor.Shared/Pages/Samples/Displays.razor.cs +++ b/src/BootstrapBlazor.Shared/Pages/Samples/Displays.razor.cs @@ -11,6 +11,7 @@ using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Linq; +using System.Threading.Tasks; namespace BootstrapBlazor.Shared.Pages { @@ -31,9 +32,13 @@ namespace BootstrapBlazor.Shared.Pages private byte[] ByteArray { get; set; } = new byte[] { 0x01, 0x12, 0x34, 0x56 }; - private static string ByteArrayFormatter(byte[] source) => Convert.ToBase64String(source); + private async Task ByteArrayFormatter(byte[] source) + { + await Task.Delay(10); + return Convert.ToBase64String(source); + } - private static string DateTimeFormatter(DateTime source) => source.ToString("yyyy-MM-dd"); + private static Task DateTimeFormatter(DateTime source) => Task.FromResult(source.ToString("yyyy-MM-dd")); /// /// OnInitialized 方法 -- Gitee From 9dbdefe6f5ed7b29dcb83d32f1fcbf9ecf116bf6 Mon Sep 17 00:00:00 2001 From: Argo-Cloud Date: Mon, 5 Apr 2021 15:38:47 +0800 Subject: [PATCH 3/4] =?UTF-8?q?feat:=20Display=20=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=90=8C=E6=AD=A5=E6=A0=BC=E5=BC=8F=E5=8C=96?= =?UTF-8?q?=E5=AD=97=E7=AC=A6=E4=B8=B2=E5=9B=9E=E8=B0=83=E5=A7=94=E6=89=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/Display/Display.razor.cs | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/BootstrapBlazor/Components/Display/Display.razor.cs b/src/BootstrapBlazor/Components/Display/Display.razor.cs index cc0b4b56d..b3896a62f 100644 --- a/src/BootstrapBlazor/Components/Display/Display.razor.cs +++ b/src/BootstrapBlazor/Components/Display/Display.razor.cs @@ -23,10 +23,16 @@ namespace BootstrapBlazor.Components protected string? CurrentTextAsString { get; set; } /// - /// 获得/设置 格式化字符串 + /// 获得/设置 异步格式化字符串 /// [Parameter] - public Func>? Formatter { get; set; } + public Func>? FormatterAsync { get; set; } + + /// + /// 获得/设置 同步格式化字符串 + /// + [Parameter] + public Func? Formatter { get; set; } /// /// 获得/设置 格式化字符串 如时间类型设置 yyyy-MM-dd @@ -50,11 +56,13 @@ namespace BootstrapBlazor.Components /// /// /// - protected virtual async Task FormatTextAsString(TValue value) => Formatter != null - ? await Formatter(value) - : (!string.IsNullOrEmpty(FormatString) && value != null - ? Utility.Format((object)value, FormatString) - : FormatText(value)); + protected virtual async Task FormatTextAsString(TValue value) => FormatterAsync != null + ? await FormatterAsync(value) + : Formatter != null + ? Formatter(value) + : (!string.IsNullOrEmpty(FormatString) && value != null + ? Utility.Format((object)value, FormatString) + : FormatText(value)); private string? FormatText(TValue value) { -- Gitee From 1f300ffbba27d6b938f40359fff02afe5ded3a4d Mon Sep 17 00:00:00 2001 From: Argo-Cloud Date: Mon, 5 Apr 2021 15:39:02 +0800 Subject: [PATCH 4/4] =?UTF-8?q?docs:=20=E6=9B=B4=E6=96=B0=E5=90=8C?= =?UTF-8?q?=E6=AD=A5=E6=A0=BC=E5=BC=8F=E5=8C=96=E5=9B=9E=E8=B0=83=E5=A7=94?= =?UTF-8?q?=E6=89=98=E7=A4=BA=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/BootstrapBlazor.Shared/Pages/Samples/Displays.razor | 2 +- src/BootstrapBlazor.Shared/Pages/Samples/Displays.razor.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/BootstrapBlazor.Shared/Pages/Samples/Displays.razor b/src/BootstrapBlazor.Shared/Pages/Samples/Displays.razor index d7f370786..6b0946400 100644 --- a/src/BootstrapBlazor.Shared/Pages/Samples/Displays.razor +++ b/src/BootstrapBlazor.Shared/Pages/Samples/Displays.razor @@ -104,7 +104,7 @@
设置 Formatter
- +
diff --git a/src/BootstrapBlazor.Shared/Pages/Samples/Displays.razor.cs b/src/BootstrapBlazor.Shared/Pages/Samples/Displays.razor.cs index 292ce4f92..05a8d592e 100644 --- a/src/BootstrapBlazor.Shared/Pages/Samples/Displays.razor.cs +++ b/src/BootstrapBlazor.Shared/Pages/Samples/Displays.razor.cs @@ -38,7 +38,7 @@ namespace BootstrapBlazor.Shared.Pages return Convert.ToBase64String(source); } - private static Task DateTimeFormatter(DateTime source) => Task.FromResult(source.ToString("yyyy-MM-dd")); + private static string DateTimeFormatter(DateTime source) => source.ToString("yyyy-MM-dd"); /// /// OnInitialized 方法 -- Gitee