From 156c1c94161171f9592923f20de4e142c845469a Mon Sep 17 00:00:00 2001 From: Michael Latouche Date: Wed, 17 Mar 2021 10:29:31 +0100 Subject: [PATCH] Revert "The Value() method for IPublishedContent was not working with the defaultValue parameter" (#9989) --- src/Umbraco.Web/PublishedContentExtensions.cs | 6 ++-- src/Umbraco.Web/PublishedPropertyExtension.cs | 33 +++++++++++++------ 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/src/Umbraco.Web/PublishedContentExtensions.cs b/src/Umbraco.Web/PublishedContentExtensions.cs index 8aa3b69fb432..d6b8f837d20a 100644 --- a/src/Umbraco.Web/PublishedContentExtensions.cs +++ b/src/Umbraco.Web/PublishedContentExtensions.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Data; using System.Linq; @@ -173,8 +173,8 @@ public static T Value(this IPublishedContent content, string alias, string cu return value; // else... if we have a property, at least let the converter return its own - // vision of 'no value' (could be an empty enumerable) - otherwise, defaultValue - return property == null ? defaultValue : property.Value(culture, segment, defaultValue: defaultValue); + // vision of 'no value' (could be an empty enumerable) - otherwise, default + return property == null ? default : property.Value(culture, segment, fallback, defaultValue); } #endregion diff --git a/src/Umbraco.Web/PublishedPropertyExtension.cs b/src/Umbraco.Web/PublishedPropertyExtension.cs index 0c3aa57cc259..6e8647db475a 100644 --- a/src/Umbraco.Web/PublishedPropertyExtension.cs +++ b/src/Umbraco.Web/PublishedPropertyExtension.cs @@ -1,4 +1,3 @@ -using System.Collections.Generic; using Umbraco.Core; using Umbraco.Core.Composing; using Umbraco.Core.Models.PublishedContent; @@ -37,13 +36,20 @@ public static T Value(this IPublishedProperty property, string culture = null // we have a value // try to cast or convert it var value = property.GetValue(culture, segment); - if (value is T valueAsT) return valueAsT; + if (value is T valueAsT) + { + return valueAsT; + } + var valueConverted = value.TryConvertTo(); - if (valueConverted) return valueConverted.Result; + if (valueConverted) + { + return valueConverted.Result; + } - // cannot cast nor convert the value, nothing we can return but 'defaultValue' + // cannot cast nor convert the value, nothing we can return but 'default' // note: we don't want to fallback in that case - would make little sense - return defaultValue; + return default; } // we don't have a value, try fallback @@ -57,15 +63,22 @@ public static T Value(this IPublishedProperty property, string culture = null var noValue = property.GetValue(culture, segment); if (noValue == null) { - return defaultValue; + return default; + } + + if (noValue is T noValueAsT) + { + return noValueAsT; } - if (noValue is T noValueAsT) return noValueAsT; var noValueConverted = noValue.TryConvertTo(); - if (noValueConverted) return noValueConverted.Result; + if (noValueConverted) + { + return noValueConverted.Result; + } - // cannot cast noValue nor convert it, nothing we can return but 'defaultValue' - return defaultValue; + // cannot cast noValue nor convert it, nothing we can return but 'default' + return default; } #endregion