From d787cb6ad99ba55fd85e9c815173c9b4d406d443 Mon Sep 17 00:00:00 2001 From: James Coxhead Date: Wed, 2 Nov 2016 21:35:42 +0000 Subject: [PATCH] Added radio button list converter --- .../RadioButtonListValueConverter.cs | 33 +++++++++++++++++++ src/Umbraco.Core/Umbraco.Core.csproj | 1 + 2 files changed, 34 insertions(+) create mode 100644 src/Umbraco.Core/PropertyEditors/ValueConverters/RadioButtonListValueConverter.cs diff --git a/src/Umbraco.Core/PropertyEditors/ValueConverters/RadioButtonListValueConverter.cs b/src/Umbraco.Core/PropertyEditors/ValueConverters/RadioButtonListValueConverter.cs new file mode 100644 index 0000000000..6ea35ba1c2 --- /dev/null +++ b/src/Umbraco.Core/PropertyEditors/ValueConverters/RadioButtonListValueConverter.cs @@ -0,0 +1,33 @@ +using System; +using Umbraco.Core.Models.PublishedContent; + +namespace Umbraco.Core.PropertyEditors.ValueConverters +{ + public class RadioButtonListValueConverter : PropertyValueConverterBase, IPropertyValueConverterMeta + { + public override bool IsConverter(PublishedPropertyType propertyType) + { + return propertyType.PropertyEditorAlias.InvariantEquals(Constants.PropertyEditors.RadioButtonListAlias); + } + + public override object ConvertDataToSource(PublishedPropertyType propertyType, object source, bool preview) + { + var intAttempt = source.TryConvertTo(); + if (intAttempt.Success) + return intAttempt.Result; + + return null; + } + + public Type GetPropertyValueType(PublishedPropertyType propertyType) + { + return typeof(int); + } + + public PropertyCacheLevel GetPropertyCacheLevel(PublishedPropertyType propertyType, + PropertyCacheValue cacheValue) + { + return PropertyCacheLevel.Content; + } + } +} diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index d47b7b6e05..882bce2cb7 100644 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -508,6 +508,7 @@ +