Sorry if this has already been answered, but I think that I don’t have enough formal education to ask this question correctly, and therefore, I don’t have the right criteria for its successful search.
I have an API that has several calls that do almost the same thing, but act on different input objects using a different method, but always form the same interface. I want to cut and paste an aspect from the processes of an API method call so that the generic code gets the same in all method calls. I managed to get a working solution using generics for input and output objects, and I make a reference to the name of the method that is called from the string. I would like method references to be strongly typed, not line-based, so renaming the method name when re-factoring would not potentially leave a “magic” string for the method name that expects to explode at run time.
Below is a very simplified version of what I'm trying to achieve.
class ARequest { }; class AResponse { }; class BRequest { }; class BResponse { }; interface IWorker { AResponse DoA(ARequest aRequest); BResponse DoB(BRequest bRequest); } class Worker : IWorker { public AResponse DoA(ARequest aRequest) { return new AResponse(); } public BResponse DoB(BRequest bRequest) { return new BResponse(); } } class Program { static void Main(string[] args) {
source share