diff --git a/app/Umbraco/Umbraco.Archetype/Models/ArchetypePublishedContent.cs b/app/Umbraco/Umbraco.Archetype/Models/ArchetypePublishedContent.cs index 793534e..b691431 100644 --- a/app/Umbraco/Umbraco.Archetype/Models/ArchetypePublishedContent.cs +++ b/app/Umbraco/Umbraco.Archetype/Models/ArchetypePublishedContent.cs @@ -11,9 +11,7 @@ namespace Archetype.Models { private ArchetypeFieldsetModel _fieldset; - private bool _initialized; - - private IPublishedProperty[] _properties; + private readonly Dictionary _properties; public ArchetypePublishedContent(ArchetypeFieldsetModel fieldset) { @@ -22,7 +20,11 @@ namespace Archetype.Models _fieldset = fieldset; - this.Initialize(); + _properties = fieldset.Properties + .ToDictionary( + x => x.Alias, + x => new ArchetypePublishedProperty(x) as IPublishedProperty, + StringComparer.InvariantCultureIgnoreCase); } internal ArchetypeFieldsetModel ArchetypeFieldset @@ -77,7 +79,8 @@ namespace Archetype.Models public IPublishedProperty GetProperty(string alias, bool recurse) { - return Properties.FirstOrDefault(x => x.PropertyTypeAlias.InvariantEquals(alias)); + IPublishedProperty property; + return _properties.TryGetValue(alias, out property) ? property : null; } public IPublishedProperty GetProperty(string alias) @@ -122,15 +125,7 @@ namespace Archetype.Models public ICollection Properties { - get - { - if (_initialized == false) - { - this.Initialize(); - } - - return _properties; - } + get { return _properties.Values; } } public int SortOrder @@ -184,23 +179,5 @@ namespace Archetype.Models : property.Value; } } - - private void Initialize() - { - if (_fieldset == null) - { - return; - } - - if (_fieldset.Properties != null) - { - _properties = _fieldset.Properties - .Select(x => new ArchetypePublishedProperty(x)) - .Cast() - .ToArray(); - } - - _initialized = true; - } } } \ No newline at end of file diff --git a/app/Umbraco/Umbraco.Archetype/Models/ArchetypePublishedProperty.cs b/app/Umbraco/Umbraco.Archetype/Models/ArchetypePublishedProperty.cs index cada797..010a9ba 100644 --- a/app/Umbraco/Umbraco.Archetype/Models/ArchetypePublishedProperty.cs +++ b/app/Umbraco/Umbraco.Archetype/Models/ArchetypePublishedProperty.cs @@ -53,30 +53,13 @@ namespace Archetype.Models { get { - if (_property == null || _rawValue == null) - { - return false; - } - - return !string.IsNullOrEmpty(_rawValue.ToString()); + return _rawValue != null && !string.IsNullOrEmpty(_rawValue.ToString()); } } public string PropertyTypeAlias { - get - { - if (_propertyType != null && !string.IsNullOrWhiteSpace(_propertyType.PropertyTypeAlias)) - { - return _propertyType.PropertyTypeAlias; - } - else if (_property != null) - { - return _property.Alias; - } - - return null; - } + get { return _property.Alias; } } public object Value