This is something I would need to do to create a flexible logic structure that I need for a class.
The class is like this:
public class myclass {
public Action myaction;
public int actionparams;
public string label;
public void myactionfunction() {
//do void parameter action
}
public void myactionfunction(int myparam) {
//do one parameter action
}
public void myactionfunction(int myparam, int myparam2) {
//do two parameter action
}
}
Well the problem I’m facing is that I will use this class where ‘myaction’ can arbitrarily require none or as much as six parameters. Since ‘Action’ needs to be defined for each parameter it’s meant to support, I could certainly define as much ‘myactions’ that I expect parameters for, but that would not be ideal, since I’d need to hardwire parameter types there.
I am hoping that there’s a way in which I could ‘simply’ reassign myaction’s type, so that in some manner I can do something like
myaction.type = Action<string,int,int>; //i know this looks bad, but should give the idea
I have read about delegate declarations, but can’t figure if there’s a way to use them for my purpose.
Thanks.
No, you can’t. You can, however, use a capture such that everything is
Action, i.e.:if these actually represent default values, then use default values!
which can be called via any of: