Created
September 11, 2014 10:18
-
-
Save bredstrup/1a7bed56a0360883fea3 to your computer and use it in GitHub Desktop.
Glass Delegate implementaion
This file contains 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
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; } | |
} |
This file contains 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
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; | |
} | |
} |
This file contains 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
public class SitecoreDelegatePropertyConfiguration : DelegatePropertyConfiguration<SitecoreDataMappingContext> | |
{ | |
/// <summary> | |
/// The default Constructor. | |
/// </summary> | |
public SitecoreDelegatePropertyConfiguration() | |
{ | |
} | |
} |
This file contains 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
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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.