Fix #12454 by having Coalesce handle null values (#12456)

* Fix #12454 by having Coalesce handle null values

* Allow null values in Html.Coalesce #12454
This commit is contained in:
Asbjørn Riis-Knudsen
2022-05-24 17:41:10 +02:00
committed by Bjarke Berg
parent 963d4c5051
commit d810d66e9a
2 changed files with 3 additions and 3 deletions

View File

@@ -89,10 +89,10 @@ public sealed class HtmlStringUtilities
return sb.ToString();
}
public string Coalesce(params object[] args)
public string Coalesce(params object?[] args)
{
var arg = args
.Select(x => x.ToString())
.Select(x => x?.ToString())
.FirstOrDefault(x => string.IsNullOrWhiteSpace(x) == false);
return arg ?? string.Empty;

View File

@@ -910,7 +910,7 @@ public static class HtmlHelperRenderExtensions
/// <summary>
/// Will take the first non-null value in the collection and return the value of it.
/// </summary>
public static string Coalesce(this IHtmlHelper helper, params object[] args)
public static string Coalesce(this IHtmlHelper helper, params object?[] args)
=> s_stringUtilities.Coalesce(args);
/// <summary>