I have a generic method that takes a request and provides a response.
public Tres DoSomething<Tres, Treq>(Tres response, Treq request)
{/*stuff*/}
But I don’t always want a response for my request, and I don’t always want to feed request data to get a response. I also don’t want to have to copy and paste methods in their entirety to make minor changes. What I want, is to be able to do this:
public Tre DoSomething<Tres>(Tres response)
{
return DoSomething<Tres, void>(response, null);
}
Is this feasible in some manner? It seems that specifically using void doesn’t work, but I’m hoping to find something analogous.
You cannot use
void, but you can useobject: it is a little inconvenience because your would-be-voidfunctions need to returnnull, but if it unifies your code, it should be a small price to pay.This inability to use
voidas a return type is at least partially responsible for a split between theFunc<...>andAction<...>families of generic delegates: had it been possible to returnvoid, allAction<X,Y,Z>would become simplyFunc<X,Y,Z,void>. Unfortunately, this is not possible.