Last active
August 29, 2015 14:04
-
-
Save ryanlewis/9eb27975d690b5f12e6c to your computer and use it in GitHub Desktop.
Property Value Converter for a array of strings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using Newtonsoft.Json; | |
using Umbraco.Core.Models.PublishedContent; | |
using Umbraco.Core.PropertyEditors; | |
namespace Epiphany.PropertyEditorValueConverters | |
{ | |
[PropertyValueType(typeof(string[]))] | |
[PropertyValueCache(PropertyCacheValue.All, PropertyCacheLevel.Content)] | |
public class StringArrayValueConverter : PropertyValueConverterBase | |
{ | |
public override bool IsConverter(PublishedPropertyType propertyType) | |
{ | |
return propertyType.PropertyEditorAlias.Equals("Epiphany.SortableStringList"); | |
} | |
public override object ConvertDataToSource(PublishedPropertyType propertyType, object source, bool preview) | |
{ | |
if (source == null) return null; | |
var sourceString = source.ToString(); | |
if (String.IsNullOrWhiteSpace(sourceString)) return null; | |
try | |
{ | |
return JsonConvert.DeserializeObject<string[]>(sourceString); | |
} | |
catch | |
{ | |
return null; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage: