Refactoring

This commit is contained in:
Stephan
2018-07-24 13:32:29 +02:00
parent 053698baf6
commit a35f67ecef
14 changed files with 168 additions and 215 deletions

View File

@@ -100,7 +100,6 @@ namespace Umbraco.Web
/// <param name="culture">The variation language.</param>
/// <param name="segment">The variation segment.</param>
/// <param name="defaultValue">The default value.</param>
/// <param name="visitedLanguages">A list of cultures already visited in looking for a value via a fall-back method.</param>
/// <returns>The value of the content's property identified by the alias, if it exists, otherwise a default value.</returns>
/// <remarks>
/// <para>The value comes from <c>IPublishedProperty</c> field <c>Value</c> ie it is suitable for use when rendering content.</para>
@@ -108,14 +107,19 @@ namespace Umbraco.Web
/// <para>If eg a numeric property wants to default to 0 when value source is empty, this has to be done in the converter.</para>
/// <para>The alias is case-insensitive.</para>
/// </remarks>
public static object Value(this IPublishedElement content, string alias, string culture = null, string segment = null, object defaultValue = default, ICollection<int> visitedLanguages = null)
public static object Value(this IPublishedElement content, string alias, string culture = null, string segment = null, object defaultValue = default)
{
var property = content.GetProperty(alias);
if (property != null && property.HasValue(culture, segment))
return property.GetValue(culture, segment);
return PublishedValueFallback.GetValue(content, alias, culture, segment, defaultValue, visitedLanguages ?? new List<int>());
// fixme defaultValue is a problem here
// assuming the value may return as an IEnumerable<int> and no defaultValue is provided, then defaultValue is null
// and if HasValue is false, what we get is 'null' - but the converter may instead have been able to return an
// empty enumerable, which would be way nicer - so we need a way to tell that 'no defaultValue has been provided'?
return PublishedValueFallback.GetValue(content, alias, culture, segment, defaultValue);
}
#endregion
@@ -131,7 +135,6 @@ namespace Umbraco.Web
/// <param name="culture">The variation language.</param>
/// <param name="segment">The variation segment.</param>
/// <param name="defaultValue">The default value.</param>
/// <param name="visitedLanguages">A list of cultures already visited in looking for a value via a fall-back method.</param>
/// <returns>The value of the content's property identified by the alias, converted to the specified type.</returns>
/// <remarks>
/// <para>The value comes from <c>IPublishedProperty</c> field <c>Value</c> ie it is suitable for use when rendering content.</para>
@@ -139,14 +142,14 @@ namespace Umbraco.Web
/// <para>If eg a numeric property wants to default to 0 when value source is empty, this has to be done in the converter.</para>
/// <para>The alias is case-insensitive.</para>
/// </remarks>
public static T Value<T>(this IPublishedElement content, string alias, string culture = null, string segment = null, T defaultValue = default, ICollection<int> visitedLanguages = null)
public static T Value<T>(this IPublishedElement content, string alias, string culture = null, string segment = null, T defaultValue = default)
{
var property = content.GetProperty(alias);
if (property != null && property.HasValue(culture, segment))
return property.Value<T>(culture, segment);
return PublishedValueFallback.GetValue<T>(content, alias, culture, segment, defaultValue, visitedLanguages ?? new List<int>());
return PublishedValueFallback.GetValue<T>(content, alias, culture, segment, defaultValue);
}
#endregion