1
public async Task QueueCallAsync(Task apiCall, RequestType requestType)
{
  // how do you forward the call to the generic implementation while omitting the result?
  await QueueCallAsync<Void>(apiCall, requestType);
}

public async Task<T> QueueCallAsync<T>(Task<T> apiCall, RequestType requestType)
{
}

So far all i achieved was recursive calls or non compilable code. I would rather wrap the generic implementation instead of duplicating the code.

Does anyone know how to tell the c# compiler to use the generic method here?

Unlike other questions I am wondering if there is a built in, intended way, to solve this without the use of reflection.

I would rather copy paste code than reflect in this case.

Dbl
  • 5,634
  • 3
  • 41
  • 66
  • Possible duplicate of [C# call Generic method dynamically](https://stackoverflow.com/questions/3834256/c-sharp-call-generic-method-dynamically) – John-Philip Jul 23 '17 at 18:41
  • 1
    How exactly are you invoking the methods? The compiler can only do so much for you as long as it knows what types are being used. You haven't shown what types you're dealing with and how you are expressing that to the compiler. – Jeff Mercado Jul 23 '17 at 19:45
  • And frankly it doesn't make sense to take `Task` which is a task that doesn't return anything and "convert" it to a `Task` which is a task that returns `T`... if anything, it should be the other way around. What exactly are you trying to accomplish here anyway? – Jeff Mercado Jul 23 '17 at 19:52
  • some are result-less calls which don't return anything, while others do return values. Not sure if we're missing each other - i do want the Task method to call the Task method - the other way around it would not even work. If there's no way to do it i'll just have to accept it i guess. – Dbl Jul 23 '17 at 23:47

1 Answers1

2

You can simply wrap task into another that returns fake int value:

async Task<int> Wrap(Task t)
{
    await t;
    return 42;
}

await QueueCallAsync<int>(Wrap(apiCall), requestType);

Side note: method name you use could be confusing for users of the method as generally tasks are already running when created and it is too later to "queue" them...

Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179
  • damn. should have thought of that. And yeah - that is fine. The fact that it is called queue is related to the purpose of the class, but thanks for the suggestion anyway. – Dbl Jul 24 '17 at 08:15