From 1d6849c578418bc6d9255b38011af8a9531239d5 Mon Sep 17 00:00:00 2001 From: Ronald Barendse Date: Tue, 9 Jun 2020 15:12:09 +0200 Subject: [PATCH 1/5] Return null in IsValue for PropertyValueLevel.Inter and Object --- .../PropertyEditors/PropertyValueConverterBase.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Umbraco.Core/PropertyEditors/PropertyValueConverterBase.cs b/src/Umbraco.Core/PropertyEditors/PropertyValueConverterBase.cs index 3b6ebc610c..1764b4b012 100644 --- a/src/Umbraco.Core/PropertyEditors/PropertyValueConverterBase.cs +++ b/src/Umbraco.Core/PropertyEditors/PropertyValueConverterBase.cs @@ -17,6 +17,10 @@ namespace Umbraco.Core.PropertyEditors { case PropertyValueLevel.Source: return value != null && (!(value is string) || string.IsNullOrWhiteSpace((string) value) == false); + case PropertyValueLevel.Inter: + return null; + case PropertyValueLevel.Object: + return null; default: throw new NotSupportedException($"Invalid level: {level}."); } From c3e58df3b5f06f517a455f09629d30b66f21d173 Mon Sep 17 00:00:00 2001 From: Ronald Barendse Date: Thu, 11 Jun 2020 00:45:12 +0200 Subject: [PATCH 2/5] Obsolete HasValue method --- .../PropertyEditors/PropertyValueConverterBase.cs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Umbraco.Core/PropertyEditors/PropertyValueConverterBase.cs b/src/Umbraco.Core/PropertyEditors/PropertyValueConverterBase.cs index 1764b4b012..57474eb2e1 100644 --- a/src/Umbraco.Core/PropertyEditors/PropertyValueConverterBase.cs +++ b/src/Umbraco.Core/PropertyEditors/PropertyValueConverterBase.cs @@ -16,7 +16,9 @@ namespace Umbraco.Core.PropertyEditors switch (level) { case PropertyValueLevel.Source: - return value != null && (!(value is string) || string.IsNullOrWhiteSpace((string) value) == false); + // the default implementation uses the old magic null & string comparisons, + // other implementations may be more clever, and/or test the final converted object values + return value != null && (!(value is string) || string.IsNullOrWhiteSpace((string)value) == false); case PropertyValueLevel.Inter: return null; case PropertyValueLevel.Object: @@ -26,16 +28,15 @@ namespace Umbraco.Core.PropertyEditors } } + [Obsolete("This method is not part of the IPropertyValueConverter contract and therefore not used, use IsValue instead.")] public virtual bool HasValue(IPublishedProperty property, string culture, string segment) { - // the default implementation uses the old magic null & string comparisons, - // other implementations may be more clever, and/or test the final converted object values var value = property.GetSourceValue(culture, segment); - return value != null && (!(value is string) || string.IsNullOrWhiteSpace((string) value) == false); + return value != null && (!(value is string) || string.IsNullOrWhiteSpace((string)value) == false); } public virtual Type GetPropertyValueType(IPublishedPropertyType propertyType) - => typeof (object); + => typeof(object); public virtual PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType propertyType) => PropertyCacheLevel.Snapshot; From eac6351c3f0336e8531d6c75126aa39c47dd5add Mon Sep 17 00:00:00 2001 From: Ronald Barendse Date: Thu, 11 Jun 2020 00:49:44 +0200 Subject: [PATCH 3/5] Simplified value check using type pattern matching --- .../PropertyEditors/PropertyValueConverterBase.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Umbraco.Core/PropertyEditors/PropertyValueConverterBase.cs b/src/Umbraco.Core/PropertyEditors/PropertyValueConverterBase.cs index 57474eb2e1..be8b0619f5 100644 --- a/src/Umbraco.Core/PropertyEditors/PropertyValueConverterBase.cs +++ b/src/Umbraco.Core/PropertyEditors/PropertyValueConverterBase.cs @@ -18,7 +18,7 @@ namespace Umbraco.Core.PropertyEditors case PropertyValueLevel.Source: // the default implementation uses the old magic null & string comparisons, // other implementations may be more clever, and/or test the final converted object values - return value != null && (!(value is string) || string.IsNullOrWhiteSpace((string)value) == false); + return value != null && (!(value is string stringValue) || !string.IsNullOrWhiteSpace(stringValue)); case PropertyValueLevel.Inter: return null; case PropertyValueLevel.Object: @@ -32,7 +32,7 @@ namespace Umbraco.Core.PropertyEditors public virtual bool HasValue(IPublishedProperty property, string culture, string segment) { var value = property.GetSourceValue(culture, segment); - return value != null && (!(value is string) || string.IsNullOrWhiteSpace((string)value) == false); + return value != null && (!(value is string stringValue) || !string.IsNullOrWhiteSpace(stringValue)); } public virtual Type GetPropertyValueType(IPublishedPropertyType propertyType) From 249b3b8609b70cad305e7accffe6b2f0203ad3ca Mon Sep 17 00:00:00 2001 From: Ronald Barendse Date: Thu, 11 Jun 2020 00:49:59 +0200 Subject: [PATCH 4/5] Update XML documentation --- .../PropertyEditors/PropertyValueConverterBase.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Umbraco.Core/PropertyEditors/PropertyValueConverterBase.cs b/src/Umbraco.Core/PropertyEditors/PropertyValueConverterBase.cs index be8b0619f5..4724295b3f 100644 --- a/src/Umbraco.Core/PropertyEditors/PropertyValueConverterBase.cs +++ b/src/Umbraco.Core/PropertyEditors/PropertyValueConverterBase.cs @@ -4,13 +4,16 @@ using Umbraco.Core.Models.PublishedContent; namespace Umbraco.Core.PropertyEditors { /// - /// Provides a default overridable implementation for that does nothing. + /// Provides a default implementation for . /// + /// public abstract class PropertyValueConverterBase : IPropertyValueConverter { + /// public virtual bool IsConverter(IPublishedPropertyType propertyType) => false; + /// public virtual bool? IsValue(object value, PropertyValueLevel level) { switch (level) @@ -35,18 +38,23 @@ namespace Umbraco.Core.PropertyEditors return value != null && (!(value is string stringValue) || !string.IsNullOrWhiteSpace(stringValue)); } + /// public virtual Type GetPropertyValueType(IPublishedPropertyType propertyType) => typeof(object); + /// public virtual PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType propertyType) => PropertyCacheLevel.Snapshot; + /// public virtual object ConvertSourceToIntermediate(IPublishedElement owner, IPublishedPropertyType propertyType, object source, bool preview) => source; + /// public virtual object ConvertIntermediateToObject(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview) => inter; + /// public virtual object ConvertIntermediateToXPath(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview) => inter?.ToString() ?? string.Empty; } From 872731f72685a8284940117b29be2b4a24cd1c81 Mon Sep 17 00:00:00 2001 From: Ronald Barendse Date: Tue, 7 Jul 2020 23:30:34 +0200 Subject: [PATCH 5/5] Update HasValue obsolete message --- src/Umbraco.Core/PropertyEditors/PropertyValueConverterBase.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Umbraco.Core/PropertyEditors/PropertyValueConverterBase.cs b/src/Umbraco.Core/PropertyEditors/PropertyValueConverterBase.cs index 4724295b3f..2ec0438328 100644 --- a/src/Umbraco.Core/PropertyEditors/PropertyValueConverterBase.cs +++ b/src/Umbraco.Core/PropertyEditors/PropertyValueConverterBase.cs @@ -31,7 +31,7 @@ namespace Umbraco.Core.PropertyEditors } } - [Obsolete("This method is not part of the IPropertyValueConverter contract and therefore not used, use IsValue instead.")] + [Obsolete("This method is not part of the IPropertyValueConverter contract, therefore not used and will be removed in future versions; use IsValue instead.")] public virtual bool HasValue(IPublishedProperty property, string culture, string segment) { var value = property.GetSourceValue(culture, segment);