Revert "Revert "The Value() method for IPublishedContent was not working with the defaultValue parameter" (#9989)"
This reverts commit 156c1c9416.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
@@ -173,8 +173,8 @@ namespace Umbraco.Web
|
||||
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, default
|
||||
return property == null ? default : property.Value<T>(culture, segment, fallback, defaultValue);
|
||||
// vision of 'no value' (could be an empty enumerable) - otherwise, defaultValue
|
||||
return property == null ? defaultValue : property.Value<T>(culture, segment, defaultValue: defaultValue);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Composing;
|
||||
using Umbraco.Core.Models.PublishedContent;
|
||||
@@ -36,20 +37,13 @@ namespace Umbraco.Web
|
||||
// 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<T>();
|
||||
if (valueConverted)
|
||||
{
|
||||
return valueConverted.Result;
|
||||
}
|
||||
if (valueConverted) return valueConverted.Result;
|
||||
|
||||
// cannot cast nor convert the value, nothing we can return but 'default'
|
||||
// cannot cast nor convert the value, nothing we can return but 'defaultValue'
|
||||
// note: we don't want to fallback in that case - would make little sense
|
||||
return default;
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
// we don't have a value, try fallback
|
||||
@@ -63,22 +57,15 @@ namespace Umbraco.Web
|
||||
var noValue = property.GetValue(culture, segment);
|
||||
if (noValue == null)
|
||||
{
|
||||
return default;
|
||||
}
|
||||
|
||||
if (noValue is T noValueAsT)
|
||||
{
|
||||
return noValueAsT;
|
||||
return defaultValue;
|
||||
}
|
||||
if (noValue is T noValueAsT) return noValueAsT;
|
||||
|
||||
var noValueConverted = noValue.TryConvertTo<T>();
|
||||
if (noValueConverted)
|
||||
{
|
||||
return noValueConverted.Result;
|
||||
}
|
||||
if (noValueConverted) return noValueConverted.Result;
|
||||
|
||||
// cannot cast noValue nor convert it, nothing we can return but 'default'
|
||||
return default;
|
||||
// cannot cast noValue nor convert it, nothing we can return but 'defaultValue'
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
Reference in New Issue
Block a user