I have the following interface that returns the generic parameter of type T using a callback...
public interface IDoWork<T>
{
T DoWork();
}
however I also have the following interface as well, but it won't invoke a callback since it returns void.
public interface IDoWork
{
void DoWork();
}
Can I combine these two interfaces and use runtime logic to determine the difference? How can I do that?
Unfortunately, they can't be combined.
You can see this in the framework - that's why there is a separate
Task
andTask<T>
class, for example.That being said, you can often share implementations in this type of scenario by using
IDoWork<object>
and passingnull
for values, etc.