I have a list of methods I wish to call and a button accompaning each and a generic method to handle the buttons.
Using the commandArgument how can I run the selected method.
E.g. Click run method1 button. In handler for button click call the method as named in commandArgument
So the string in the CommandArgument matches the name of a method? If you must do this then you could use reflection. I’m assuming you’ve basically got a single button click event for each button or you wouldn’t be asking this:
Although this looks like a massive code smell. Why do you have to do it this way? Why can you not just give each button a separate event handler and call each method directly?
Alternatively, why not use a switch statement on the argument: