Last active
August 29, 2015 14:22
-
-
Save micklaw/c159c4d05d09dd4d341c to your computer and use it in GitHub Desktop.
Archetype Value Resolver
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
namespace Our.Umbraco.Ditto.Resolvers.Archetype.Resolvers | |
{ | |
public class ArchetypeValueResolver : DittoValueResolver<ArchetypeResolverAttribute> | |
{ | |
public override object ResolveValue(ITypeDescriptorContext context, ArchetypeResolverAttribute attribute, CultureInfo culture) | |
{ | |
var content = context.Instance as IPublishedContent; | |
var descriptor = context.PropertyDescriptor; | |
if (content != null && descriptor != null) | |
{ | |
var alias = attribute.PropertyAlias ?? descriptor.DisplayName; | |
var property = content.GetProperty(alias); | |
if (property.HasValue) | |
{ | |
var archetype = property.Value as ArchetypeModel; | |
if (archetype != null) | |
{ | |
return archetype.As(descriptor.PropertyType, culture, content); | |
} | |
} | |
} | |
return null; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment