Just a quick update on my previous posting following one of the comments made by den Ben
just out of curiosity... why wouldn't you
dispatcher.Add<SaveDocumentRequest>(s =>
{
s.Document = document;
s.UserID = userID;
});
He's absolutely right. Using a Func forced me to (mis)use the params keyword as you are not allowed to use the above syntax with the old code:
public virtual IDispatcher Add<TRequestType>(params Func<TRequestType, object>[] funcs)
where TRequestType : Request, new()
{
TRequestType request = new TRequestType();
foreach (var func in funcs)
{
func.Invoke(request);
}
AddRequest(request, false);
return this;
}
I actually had noticed the code not using the return value by the func but disregarded it as I was a bit too happy with the "elegance" of my inital solution.
But I think (and I think you'll agree) that using an Action is much cleaner here:
public virtual IDispatcher Add<TRequestType>(Action<TRequestType> action)
where TRequestType : Request, new()
{
TRequestType request = new TRequestType();
action(request);
AddRequest(request, false);
return this;
}
Thanks den Ben!