Created
February 10, 2011 04:33
-
-
Save jmarnold/819950 to your computer and use it in GitHub Desktop.
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
public interface IPartialDecorator<T> | |
where T : class | |
{ | |
T Enrich(T target); | |
} |
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
public class PartialAction<T> | |
where T : class | |
{ | |
private readonly IContainer _container; | |
public PartialAction(IContainer container) | |
{ | |
_container = container; | |
} | |
public T Execute(T target) | |
{ | |
_container | |
.GetAllInstances<IPartialDecorator<T>>() | |
.Each(d => | |
{ | |
// allow classes to hook in and build up model properties | |
target = d.Enrich(target); | |
}); | |
return target; | |
} | |
} |
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
// hook this up with an Actions.FindWith<PartialActionSource>() in your FubuRegistry | |
public class PartialActionSource : IActionSource | |
{ | |
public IEnumerable<ActionCall> FindActions(TypePool types) | |
{ | |
return types | |
.TypesMatching(t => t.HasAttribute<PartialModelAttribute>() && !t.GetGenericArguments().Any()) | |
.Select(m => | |
{ | |
var actionType = typeof(PartialAction<>).MakeGenericType(m); | |
return new ActionCall(actionType, actionType.GetExecuteMethod()); // just grabs the method named "Execute" | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment