Otis wrote:
big problem: how am I going to call the delegates in generic code if they require parameters? I have to test it, but I can't just pass an array.
I can solve the variable parameter specification when adding the delegate, using params ... . But I can't call the delegate, at least I don't see how to do that.
I'm not exactly sure what you mean by generic code
, but maybe I was thinking about it from a slightly different angle.
Regarding the adding of action stored procedures to the UnitOfWork, lets call the add method "AddActionProcedure"...
Say we have a generated action stored procedure called MyActionProc which takes 2 parameters like:
ActionProcedures.MyActionProc (string param1, string param2);
A new template is required to generate the delegates for each of the ActionProcedure methods. For the above example it would be called "MyActionProcDelegate" which has the same signature as MyActionProc. These are generated into a file called "ActionProcedureDelegates.cs".
delegate MyActionProcDelegate(string param1, string param2);
UnitOfWork.AddActionProcedure then takes an instance of delegate as a parameter. Note the param type Delegate with a capital "D" which refers the to base class. Maybe you need "MulticastDelegate" here, I'm not sure.
public void AddActionProcedure(Delegate actionProcedureDelegate)
{
...
}
and is called like this:
UnitOfWork uow = new UnitOfWork();
uow.AddActionProcedure(new MyActionProcDelegate (ActionProcedures.MyActionProc (param1, param2));
uow.Commit();
Of course the new Template could provide further cleanup of the above usage by providing a helper method like:
uow.AddActionProcedure(ActionProcedureDelegates.MyActionProc(param1, param2));
Within the Commit method, you can now simply invoke the queued Delegate instance as normal.
I haven't tested any of this either
but it looks okay on screen! (I was about to say on paper). Maybe you'll find a flaw...
Marcus