I have the following interface:
interface MyInterface {
void Method1(string someArg);
void Method2(int anotherArg);
}
I have some arbitrary amount of implementations of this interface, I want to loop through them all and invoke method[x] with a given argument.
I could do this with a loop, such as:
foreach (var myImplementation in myImplementations)
{
myImplementation.Method1("ok");
}
But, assuming this were in a private method, how can I pass the Method1("ok");
part as an argument itself?
private void InvokeSomething(/*which arg here?*/)
{
foreach (var myImplementation in myImplementations)
{
myImplementation /* how can I make this part implicit? */
}
}
Please assume there are many methods, and there are many implementations (i.e. I want to avoid a switch
or an if
here)