Deal with more fixme
This commit is contained in:
@@ -69,25 +69,6 @@ namespace Umbraco.Web
|
||||
return prop != null && prop.HasValue(culture, segment);
|
||||
}
|
||||
|
||||
// fixme - .Value() refactoring - in progress
|
||||
// missing variations...
|
||||
|
||||
/// <summary>
|
||||
/// Returns one of two strings depending on whether the content has a value for a property identified by its alias.
|
||||
/// </summary>
|
||||
/// <param name="content">The content.</param>
|
||||
/// <param name="alias">The property alias.</param>
|
||||
/// <param name="valueIfTrue">The value to return if the content has a value for the property.</param>
|
||||
/// <param name="valueIfFalse">The value to return if the content has no value for the property.</param>
|
||||
/// <returns>Either <paramref name="valueIfTrue"/> or <paramref name="valueIfFalse"/> depending on whether the content
|
||||
/// has a value for the property identified by the alias.</returns>
|
||||
public static IHtmlString IfValue(this IPublishedElement content, string alias, string valueIfTrue, string valueIfFalse = null)
|
||||
{
|
||||
return content.HasValue(alias)
|
||||
? new HtmlString(valueIfTrue)
|
||||
: new HtmlString(valueIfFalse ?? string.Empty);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Value
|
||||
@@ -165,57 +146,6 @@ namespace Umbraco.Web
|
||||
|
||||
#endregion
|
||||
|
||||
#region Value or Umbraco.Field - WORK IN PROGRESS
|
||||
|
||||
// fixme - .Value() refactoring - in progress
|
||||
// trying to reproduce Umbraco.Field so we can get rid of it
|
||||
//
|
||||
// what we want:
|
||||
// - alt aliases
|
||||
// - recursion
|
||||
// - default value
|
||||
// - before & after (if value)
|
||||
//
|
||||
// convertLineBreaks: should be an extension string.ConvertLineBreaks()
|
||||
// stripParagraphs: should be an extension string.StripParagraphs()
|
||||
// format: should use the standard .ToString(format)
|
||||
//
|
||||
// see UmbracoComponentRenderer.Field - which is ugly ;-(
|
||||
|
||||
// recurse first, on each alias (that's how it's done in Field)
|
||||
//
|
||||
// there is no strongly typed recurse, etc => needs to be in ModelsBuilder?
|
||||
|
||||
// that one can only happen in ModelsBuilder as that's where the attributes are defined
|
||||
// the attribute that carries the alias is in ModelsBuilder!
|
||||
//public static TValue Value<TModel, TValue>(this TModel content, Expression<Func<TModel, TValue>> propertySelector, ...)
|
||||
// where TModel : IPublishedElement
|
||||
//{
|
||||
// PropertyInfo pi = GetPropertyFromExpression(propertySelector);
|
||||
// var attr = pi.GetCustomAttribute<ImplementPropertyAttribute>();
|
||||
// var alias = attr.Alias;
|
||||
// return content.Value<TValue>(alias, ...)
|
||||
//}
|
||||
|
||||
// recurse should be implemented via fallback
|
||||
|
||||
// todo - that one should be refactored, missing culture and so many things
|
||||
public static IHtmlString Value<T>(this IPublishedElement content, string aliases, Func<T, string> format, string alt = "")
|
||||
{
|
||||
if (format == null) format = x => x.ToString();
|
||||
|
||||
var property = aliases.Split(',')
|
||||
.Where(x => string.IsNullOrWhiteSpace(x) == false)
|
||||
.Select(x => content.GetProperty(x.Trim()))
|
||||
.FirstOrDefault(x => x != null);
|
||||
|
||||
return property != null
|
||||
? new HtmlString(format(property.Value<T>()))
|
||||
: new HtmlString(alt);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ToIndexedArray
|
||||
|
||||
public static IndexedArrayItem<TContent>[] ToIndexedArray<TContent>(this IEnumerable<TContent> source)
|
||||
|
||||
Reference in New Issue
Block a user