Created
September 18, 2018 14:18
-
-
Save haukurk/b464f169f6d5dc237442f3a49b429f5a to your computer and use it in GitHub Desktop.
PublishContentExtensions
This file contains hidden or 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 Our.Umbraco.Vorto.Extensions; | |
using System; | |
using Umbraco.Core.Models; | |
namespace Umbraco.Custom.Extensions | |
{ | |
public static class PublishContentExtensions | |
{ | |
public static T GetNonNullableVortoValue<T>(this IPublishedContent content, string propertyAlias, T defaultValue, string cultureName = null) | |
{ | |
T vortoValue; | |
try | |
{ | |
if (String.IsNullOrEmpty(cultureName)) | |
{ | |
vortoValue = content.GetVortoValue<T>(propertyAlias, defaultValue: defaultValue); | |
} | |
else | |
{ | |
vortoValue = content.GetVortoValue<T>(propertyAlias, defaultValue: defaultValue, cultureName: cultureName); | |
} | |
} | |
catch (Exception) /* If Vorto throws an expcetion we fallback to default value */ | |
{ | |
vortoValue = defaultValue; | |
} | |
return vortoValue; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment