diff --git a/src/BootstrapBlazor/Components/Display/Display.razor.cs b/src/BootstrapBlazor/Components/Display/Display.razor.cs index c2ab3a977f06c8462ac29cfd234904e841720653..be5341ec95b3a01d9f06ff1884cc1230e0ffa101 100644 --- a/src/BootstrapBlazor/Components/Display/Display.razor.cs +++ b/src/BootstrapBlazor/Components/Display/Display.razor.cs @@ -60,28 +60,27 @@ namespace BootstrapBlazor.Components protected virtual async Task FormatTextAsString(TValue value) => FormatterAsync != null ? await FormatterAsync(value) : (!string.IsNullOrEmpty(FormatString) && value != null - ? Utility.Format((object)value, FormatString) - : FormatText(value)); + ? Utility.Format(value, FormatString) + : value == null + ? FormatValueString() + : FormatText(value)); - private string? FormatText(TValue value) + private string FormatText(TValue value) { - var ret = ""; - if (value != null) + string ret; + var type = typeof(TValue); + if (type.IsEnum()) { - var type = NullableUnderlyingType ?? typeof(TValue); - if (type.IsEnum()) - { - ret = type.ToEnumDisplayName(value.ToString()); - } - else if (type.IsArray) - { - ret = ConvertArrayToString(value); - } - else if (type.IsGenericType && type.IsAssignableTo(typeof(IEnumerable))) - { - // 泛型集合 IEnumerable - ret = ConvertEnumerableToString(value); - } + ret = type.ToEnumDisplayName(value!.ToString()); + } + else if (type.IsArray) + { + ret = ConvertArrayToString(value); + } + else if (type.IsGenericType && type.IsAssignableTo(typeof(IEnumerable))) + { + // 泛型集合 IEnumerable + ret = ConvertEnumerableToString(value); } else {