I am working on a project that needs to be very extendable. It is about performing actions on the basis of a string code or an enum value. I am now using a switch-case statement and calling the methods manually.
What I would like to do is loop through the database records (and eventually get the enum value or string code), call the method "PerformAction" and make it possible to implement the classes or methods later.
public bool PerformAction(ActionToPerform actionToPerform) { bool isPerformed = false; switch (actionToPerform.Action.Code) { case "MAIL": isPerformed = Actions.SendEmail(actionToPerform); break; case "RESTART": isPerformed = Actions.RestartSendport(); break; case "EVENT-LOG": isPerformed = Actions.AddToEventLog(); break; } //Do some more return isPerformed; } I want to be able to implement the actions like SendEmail, RestartSendport and AddToEventLog later. I know this can somehow be done using reflection and giving the methods the name of the CODE (e.g. "MAIL.cs") so I can avoid using the switch case and perform one single call.
I need this to be very dynamic and in another library, so I was wondering if there is a best practice or a nice design pattern for this kind of problem.