Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Glass Delegate implementaion
public class DelegatePropertyConfiguration<T>: AbstractPropertyConfiguration where T : AbstractDataMappingContext
{
/// <summary>
/// The default Constructor.
/// </summary>
public DelegatePropertyConfiguration()
{
}
public Action<T> MapToCmsAction { get; set; }
public Func<T, object> MapToPropertyAction { get; set; }
}
public class SitecoreDelegate<T> : AbstractPropertyBuilder<T, SitecoreDelegatePropertyConfiguration>
{
public SitecoreDelegate(Expression<Func<T, object>> ex): base(ex){}
public SitecoreDelegate<T> SetValue(Action<SitecoreDataMappingContext> mapAction)
{
this.Configuration.MapToCmsAction = mapAction;
return this;
}
public SitecoreDelegate<T> GetValue(Func<SitecoreDataMappingContext,object> mapFunction)
{
this.Configuration.MapToPropertyAction = mapFunction;
return this;
}
}
public class SitecoreDelegatePropertyConfiguration : DelegatePropertyConfiguration<SitecoreDataMappingContext>
{
/// <summary>
/// The default Constructor.
/// </summary>
public SitecoreDelegatePropertyConfiguration()
{
}
}
public static class SitecoreTypeExtensions
{
public static SitecoreDelegate<T> Delegate<T>(this SitecoreType<T> type, Expression<Func<T, object>> ex)
{
var sitecoreDelegate = new SitecoreDelegate<T>(ex);
type.Config.AddProperty(sitecoreDelegate.Configuration);
return sitecoreDelegate;
}
}
@cardinal252

This comment has been minimized.

Copy link

cardinal252 commented Sep 11, 2014

I have nuget packages available for this as well as glass using Agnostic Ioc on private feeds and my mapping framework if you would like to mess around some more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.