diff --git a/appveyor.yml b/appveyor.yml index a06e7e0..0208127 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,5 +1,5 @@ # version format -version: 1.5.0.{build} +version: 1.5.1.{build} # UMBRACO_PACKAGE_PRERELEASE_SUFFIX if a rtm release build this should be blank, otherwise if empty will default to alpha # example UMBRACO_PACKAGE_PRERELEASE_SUFFIX=beta diff --git a/src/Our.Umbraco.Vorto/Extensions/IPublishedContentExtensions.cs b/src/Our.Umbraco.Vorto/Extensions/IPublishedContentExtensions.cs index 7b6aef6..c02d43a 100644 --- a/src/Our.Umbraco.Vorto/Extensions/IPublishedContentExtensions.cs +++ b/src/Our.Umbraco.Vorto/Extensions/IPublishedContentExtensions.cs @@ -24,6 +24,7 @@ private static bool DoInnerHasVortoValue(this IPublishedContent content, string { var bestMatchCultureName = vortoModel.FindBestMatchCulture(cultureName); if (!bestMatchCultureName.IsNullOrWhiteSpace() + && vortoModel.Values.ContainsKey(bestMatchCultureName) && vortoModel.Values[bestMatchCultureName] != null && !vortoModel.Values[bestMatchCultureName].ToString().IsNullOrWhiteSpace()) return true; @@ -72,10 +73,13 @@ private static T DoInnerGetVortoValue(this IPublishedContent content, string { // Get the serialized value var bestMatchCultureName = vortoModel.FindBestMatchCulture(cultureName); - var value = vortoModel.Values[bestMatchCultureName]; - - if (value != null && !value.ToString().IsNullOrWhiteSpace()) + if (!bestMatchCultureName.IsNullOrWhiteSpace() + && vortoModel.Values.ContainsKey(bestMatchCultureName) + && vortoModel.Values[bestMatchCultureName] != null + && !vortoModel.Values[bestMatchCultureName].ToString().IsNullOrWhiteSpace()) { + var value = vortoModel.Values[bestMatchCultureName]; + // Get target datatype var targetDataType = VortoHelper.GetTargetDataTypeDefinition(vortoModel.DtdGuid); @@ -85,30 +89,28 @@ private static T DoInnerGetVortoValue(this IPublishedContent content, string // just ignoring these when looking up converters. // NB: IPropertyEditorValueConverter not to be confused with // IPropertyValueConverter which are the ones most people are creating - var properyType = CreateDummyPropertyType(targetDataType.Id, targetDataType.PropertyEditorAlias, content.ContentType); + var properyType = CreateDummyPropertyType( + targetDataType.Id, + targetDataType.PropertyEditorAlias, + content.ContentType); - // Try convert data to source - var converted = properyType.ConvertDataToSource(value, false); - if (converted is T) - return (T)converted; + // Try convert source to object + var converted = properyType.ConvertSourceToObject(value, false); + if (converted is T) return (T)converted; var convertAttempt = converted.TryConvertTo(); - if (convertAttempt.Success) - return convertAttempt.Result; + if (convertAttempt.Success) return convertAttempt.Result; - // Try convert source to object - converted = properyType.ConvertSourceToObject(value, false); - if (converted is T) - return (T)converted; + // Try convert data to source + converted = properyType.ConvertDataToSource(value, false); + if (converted is T) return (T)converted; convertAttempt = converted.TryConvertTo(); - if (convertAttempt.Success) - return convertAttempt.Result; + if (convertAttempt.Success) return convertAttempt.Result; // Try just converting var convertAttempt2 = value.TryConvertTo(); - if (convertAttempt2.Success) - return convertAttempt2.Result; + if (convertAttempt2.Success) return convertAttempt2.Result; // Still not right type so return default value return defaultValue;