Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
mattbrailsford committed Mar 3, 2016
2 parents 5fbb52f + 18cd97e commit da8d713
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
38 changes: 20 additions & 18 deletions src/Our.Umbraco.Vorto/Extensions/IPublishedContentExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -72,10 +73,13 @@ private static T DoInnerGetVortoValue<T>(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);

Expand All @@ -85,30 +89,28 @@ private static T DoInnerGetVortoValue<T>(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<T>();
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<T>();
if (convertAttempt.Success)
return convertAttempt.Result;
if (convertAttempt.Success) return convertAttempt.Result;

// Try just converting
var convertAttempt2 = value.TryConvertTo<T>();
if (convertAttempt2.Success)
return convertAttempt2.Result;
if (convertAttempt2.Success) return convertAttempt2.Result;

// Still not right type so return default value
return defaultValue;
Expand Down

0 comments on commit da8d713

Please sign in to comment.