From d9374c34d162f67b05efdc65b9af8994d03f06ad Mon Sep 17 00:00:00 2001 From: Stephan Date: Mon, 31 Mar 2014 19:16:44 +0200 Subject: [PATCH] Add IPropertyValueConverterMeta interface Conflicts: src/Umbraco.Core/Models/PublishedContent/PublishedPropertyType.cs src/Umbraco.Core/Umbraco.Core.csproj --- .../PublishedContent/PublishedPropertyType.cs | 33 +++++++++++++++---- .../IPropertyValueConverterMeta.cs | 29 ++++++++++++++++ src/Umbraco.Core/Umbraco.Core.csproj | 1 + 3 files changed, 56 insertions(+), 7 deletions(-) create mode 100644 src/Umbraco.Core/PropertyEditors/IPropertyValueConverterMeta.cs diff --git a/src/Umbraco.Core/Models/PublishedContent/PublishedPropertyType.cs b/src/Umbraco.Core/Models/PublishedContent/PublishedPropertyType.cs index b2645ec30f..f4b1597a7d 100644 --- a/src/Umbraco.Core/Models/PublishedContent/PublishedPropertyType.cs +++ b/src/Umbraco.Core/Models/PublishedContent/PublishedPropertyType.cs @@ -222,19 +222,38 @@ namespace Umbraco.Core.Models.PublishedContent } } - + + var converterMeta = _converter as IPropertyValueConverterMeta; + // get the cache levels, quietely fixing the inconsistencies (no need to throw, really) - _sourceCacheLevel = GetCacheLevel(_converter, PropertyCacheValue.Source); - _objectCacheLevel = GetCacheLevel(_converter, PropertyCacheValue.Object); - _objectCacheLevel = GetCacheLevel(_converter, PropertyCacheValue.XPath); + if (converterMeta != null) + { + _sourceCacheLevel = converterMeta.GetPropertyCacheLevel(this, PropertyCacheValue.Source); + _objectCacheLevel = converterMeta.GetPropertyCacheLevel(this, PropertyCacheValue.Object); + _objectCacheLevel = converterMeta.GetPropertyCacheLevel(this, PropertyCacheValue.XPath); + } + else + { + _sourceCacheLevel = GetCacheLevel(_converter, PropertyCacheValue.Source); + _objectCacheLevel = GetCacheLevel(_converter, PropertyCacheValue.Object); + _objectCacheLevel = GetCacheLevel(_converter, PropertyCacheValue.XPath); + } if (_objectCacheLevel < _sourceCacheLevel) _objectCacheLevel = _sourceCacheLevel; if (_xpathCacheLevel < _sourceCacheLevel) _xpathCacheLevel = _sourceCacheLevel; + // get the CLR type of the converted value if (_converter != null) { - var attr = _converter.GetType().GetCustomAttribute(false); - if (attr != null) - _clrType = attr.Type; + if (converterMeta != null) + { + _clrType = converterMeta.GetPropertyValueType(this); + } + else + { + var attr = _converter.GetType().GetCustomAttribute(false); + if (attr != null) + _clrType = attr.Type; + } } } diff --git a/src/Umbraco.Core/PropertyEditors/IPropertyValueConverterMeta.cs b/src/Umbraco.Core/PropertyEditors/IPropertyValueConverterMeta.cs new file mode 100644 index 0000000000..4c545c2f50 --- /dev/null +++ b/src/Umbraco.Core/PropertyEditors/IPropertyValueConverterMeta.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Umbraco.Core.Models.PublishedContent; + +namespace Umbraco.Core.PropertyEditors +{ + /// + /// Provides published content properties converter meta data. + /// + public interface IPropertyValueConverterMeta : IPropertyValueConverter + { + /// + /// Gets the type of values returned by the converter. + /// + /// The property type. + /// The CLR type of values returned by the converter. + Type GetPropertyValueType(PublishedPropertyType propertyType); + + /// + /// Gets the property cache level of a specified value. + /// + /// The property type. + /// The property value. + /// The property cache level of the specified value. + PropertyCacheLevel GetPropertyCacheLevel(PublishedPropertyType propertyType, PropertyCacheValue cacheValue); + } +} diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index ab90ce6a90..bc0fdff936 100644 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -407,6 +407,7 @@ +