From 73763317618380209c0b0551761ef313c8b28933 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Tue, 19 Nov 2019 10:50:01 +0100 Subject: [PATCH] AB3789 - Moved some of the propertyEditor stuff --- .../DefaultPropertyValueConverterAttribute.cs | 2 +- .../PropertyEditors/PropertyEditorTagsExtensions.cs | 0 .../ValueConverters/CheckboxListValueConverter.cs | 11 +++++++++-- src/Umbraco.Core/Umbraco.Core.csproj | 2 -- .../PropertyEditorValueConverterTests.cs | 3 ++- 5 files changed, 12 insertions(+), 6 deletions(-) rename src/{Umbraco.Core => Umbraco.Abstractions}/PropertyEditors/DefaultPropertyValueConverterAttribute.cs (95%) rename src/{Umbraco.Core => Umbraco.Abstractions}/PropertyEditors/PropertyEditorTagsExtensions.cs (100%) rename src/{Umbraco.Core => Umbraco.Abstractions}/PropertyEditors/ValueConverters/CheckboxListValueConverter.cs (78%) diff --git a/src/Umbraco.Core/PropertyEditors/DefaultPropertyValueConverterAttribute.cs b/src/Umbraco.Abstractions/PropertyEditors/DefaultPropertyValueConverterAttribute.cs similarity index 95% rename from src/Umbraco.Core/PropertyEditors/DefaultPropertyValueConverterAttribute.cs rename to src/Umbraco.Abstractions/PropertyEditors/DefaultPropertyValueConverterAttribute.cs index 4099979da3..5922457b43 100644 --- a/src/Umbraco.Core/PropertyEditors/DefaultPropertyValueConverterAttribute.cs +++ b/src/Umbraco.Abstractions/PropertyEditors/DefaultPropertyValueConverterAttribute.cs @@ -6,7 +6,7 @@ namespace Umbraco.Core.PropertyEditors /// Indicates that this is a default property value converter (shipped with Umbraco) /// [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)] - internal class DefaultPropertyValueConverterAttribute : Attribute + public class DefaultPropertyValueConverterAttribute : Attribute { public DefaultPropertyValueConverterAttribute() { diff --git a/src/Umbraco.Core/PropertyEditors/PropertyEditorTagsExtensions.cs b/src/Umbraco.Abstractions/PropertyEditors/PropertyEditorTagsExtensions.cs similarity index 100% rename from src/Umbraco.Core/PropertyEditors/PropertyEditorTagsExtensions.cs rename to src/Umbraco.Abstractions/PropertyEditors/PropertyEditorTagsExtensions.cs diff --git a/src/Umbraco.Core/PropertyEditors/ValueConverters/CheckboxListValueConverter.cs b/src/Umbraco.Abstractions/PropertyEditors/ValueConverters/CheckboxListValueConverter.cs similarity index 78% rename from src/Umbraco.Core/PropertyEditors/ValueConverters/CheckboxListValueConverter.cs rename to src/Umbraco.Abstractions/PropertyEditors/ValueConverters/CheckboxListValueConverter.cs index dd2dfb49e7..ee1cd2062d 100644 --- a/src/Umbraco.Core/PropertyEditors/ValueConverters/CheckboxListValueConverter.cs +++ b/src/Umbraco.Abstractions/PropertyEditors/ValueConverters/CheckboxListValueConverter.cs @@ -1,14 +1,21 @@ using System; using System.Collections.Generic; using System.Linq; -using Newtonsoft.Json; using Umbraco.Core.Models.PublishedContent; +using Umbraco.Core.Serialization; namespace Umbraco.Core.PropertyEditors.ValueConverters { [DefaultPropertyValueConverter] public class CheckboxListValueConverter : PropertyValueConverterBase { + private readonly IJsonSerializer _jsonSerializer; + + public CheckboxListValueConverter(IJsonSerializer jsonSerializer) + { + _jsonSerializer = jsonSerializer; + } + public override bool IsConverter(IPublishedPropertyType propertyType) => propertyType.EditorAlias.InvariantEquals(Constants.PropertyEditors.Aliases.CheckBoxList); @@ -25,7 +32,7 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters if (string.IsNullOrEmpty(sourceString)) return Enumerable.Empty(); - return JsonConvert.DeserializeObject(sourceString); + return _jsonSerializer.Deserialize(sourceString); } } } diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index 3a113be9f4..098d1df110 100755 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -220,7 +220,6 @@ - @@ -357,7 +356,6 @@ - diff --git a/src/Umbraco.Tests/PropertyEditors/PropertyEditorValueConverterTests.cs b/src/Umbraco.Tests/PropertyEditors/PropertyEditorValueConverterTests.cs index 43c1a83d33..ad07501296 100644 --- a/src/Umbraco.Tests/PropertyEditors/PropertyEditorValueConverterTests.cs +++ b/src/Umbraco.Tests/PropertyEditors/PropertyEditorValueConverterTests.cs @@ -7,6 +7,7 @@ using Umbraco.Core.Models; using Umbraco.Core.Models.PublishedContent; using Umbraco.Core.PropertyEditors; using Umbraco.Core.PropertyEditors.ValueConverters; +using Umbraco.Core.Serialization; using Umbraco.Web.PropertyEditors; using Umbraco.Web.PropertyEditors.ValueConverters; @@ -72,7 +73,7 @@ namespace Umbraco.Tests.PropertyEditors [TestCase(null, new string[] { })] public void CanConvertCheckboxListPropertyEditor(object value, IEnumerable expected) { - var converter = new CheckboxListValueConverter(); + var converter = new CheckboxListValueConverter(new JsonNetSerializer()); var result = converter.ConvertIntermediateToObject(null, null, PropertyCacheLevel.Unknown, value, false); Assert.AreEqual(expected, result);