E
E
embiid2021-07-19 23:56:09
C++ / C#
embiid, 2021-07-19 23:56:09

How to return a generic value?

How to return generic value?
I can't understand why I can't return return TResponse in the GetAsync method? How to get it back...?

public Task<TResponse> GetAsync<TResponse>(RequestParameters parameters)
        {
            AddAuthorizationHeader(parameters);
            return TResponse;
        }


Here, for example, I just override the virtual method from the heir:
public override Task<HttpResponseMessage> GetAsync(RequestParameters parameters)
        {
            AddAuthorizationHeader(parameters);
            return base.GetAsync(parameters);
        }

        private RequestParameters AddAuthorizationHeader(RequestParameters parameters)
        {
            parameters.Headers = new Dictionary<string, IEnumerable<string>>
                { { "Authorization", new[] { credentials.Token } } };

            return parameters;
        }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vasily Bannikov, 2021-07-20
@embiid

Because TResponse is a type, but you need to return a value of type Task<TResponse>.
This TResponse must be obtained from somewhere.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question