Allowed IfNullOrWhiteSpace to take null input. (#12328)

This commit is contained in:
Andy Butland
2022-05-02 12:21:57 +02:00
committed by GitHub
parent 140029c38c
commit 46373ebfb0
5 changed files with 7 additions and 7 deletions

View File

@@ -365,7 +365,7 @@ namespace Umbraco.Extensions
/// returns <see langword="false"/>.</returns>
public static bool IsNullOrWhiteSpace(this string? value) => string.IsNullOrWhiteSpace(value);
public static string? IfNullOrWhiteSpace(this string str, string? defaultValue)
public static string? IfNullOrWhiteSpace(this string? str, string? defaultValue)
{
return str.IsNullOrWhiteSpace() ? defaultValue : str;
}

View File

@@ -1,4 +1,4 @@
using Umbraco.Extensions;
using Umbraco.Extensions;
namespace Umbraco.Cms.Core.Services
{
@@ -22,9 +22,9 @@ namespace Umbraco.Cms.Core.Services
/// </remarks>
public Ordering(string? orderBy, Direction direction = Direction.Ascending, string? culture = null, bool isCustomField = false)
{
OrderBy = orderBy?.IfNullOrWhiteSpace(null); // empty is null and means, not sorting
OrderBy = orderBy.IfNullOrWhiteSpace(null); // empty is null and means, not sorting
Direction = direction;
Culture = culture?.IfNullOrWhiteSpace(string.Empty); // empty is "" and means, invariant
Culture = culture.IfNullOrWhiteSpace(string.Empty); // empty is "" and means, invariant
IsCustomField = isCustomField;
}

View File

@@ -286,7 +286,7 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
}
text = text.Substring(1);
return CultureDictionary[text]?.IfNullOrWhiteSpace(text);
return CultureDictionary[text].IfNullOrWhiteSpace(text);
}
protected ActionResult<TContentType?> PerformPostSave<TContentTypeDisplay, TContentTypeSave, TPropertyType>(

View File

@@ -252,7 +252,7 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
var culture = queryStrings["culture"].TryConvertTo<string>();
//if this is null we'll set it to the default.
var cultureVal = (culture.Success ? culture.Result : null)?.IfNullOrWhiteSpace(_localizationService.GetDefaultLanguageIsoCode());
var cultureVal = (culture.Success ? culture.Result : null).IfNullOrWhiteSpace(_localizationService.GetDefaultLanguageIsoCode());
// set names according to variations
foreach (var entity in result.Value!)

View File

@@ -116,7 +116,7 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
nodes.AddRange(_memberTypeService.GetAll()
.Select(memberType =>
CreateTreeNode(memberType.Alias, id, queryStrings, memberType.Name, memberType.Icon?.IfNullOrWhiteSpace(Constants.Icons.Member), true,
CreateTreeNode(memberType.Alias, id, queryStrings, memberType.Name, memberType.Icon.IfNullOrWhiteSpace(Constants.Icons.Member), true,
queryStrings.GetRequiredValue<string>("application") + TreeAlias.EnsureStartsWith('/') + "/list/" + memberType.Alias)));
}