Skip to content

Instantly share code, notes, and snippets.

@micklaw
Last active August 29, 2015 14:22
Show Gist options
  • Save micklaw/c159c4d05d09dd4d341c to your computer and use it in GitHub Desktop.
Save micklaw/c159c4d05d09dd4d341c to your computer and use it in GitHub Desktop.
Archetype Value Resolver
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