diff --git a/app/Umbraco/Umbraco.Archetype/Models/Fieldset.cs b/app/Umbraco/Umbraco.Archetype/Models/Fieldset.cs index 72d782f..e2aeaee 100644 --- a/app/Umbraco/Umbraco.Archetype/Models/Fieldset.cs +++ b/app/Umbraco/Umbraco.Archetype/Models/Fieldset.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Umbraco.Core; namespace Archetype.Umbraco.Models { @@ -16,5 +17,30 @@ namespace Archetype.Umbraco.Models Properties = new List(); } + public string GetValue(string propertyAlias) + { + return GetValue(propertyAlias); + } + + public T GetValue(string propertyAlias) + { + var property = GetProperty(propertyAlias); + + if (property == null || string.IsNullOrEmpty(property.Value)) + return default(T); + + var convertAttempt = property.Value.TryConvertTo(); + + if (convertAttempt.Success) + return convertAttempt.Result; + + return default(T); + } + + private Property GetProperty(string propertyAlias) + { + return Properties.FirstOrDefault(p => p.Alias.InvariantEquals(propertyAlias)); + } + } }