How to pass and receive a type as a parameter

Federico Luna salazar 21 Reputation points
2021-09-22T18:46:11.657+00:00

Hello.

How to pass a type to a method as a parameter?

I have this method:

            private string CallApi(string api, string method)
            {
                var client = new RestClient(api);
                var request = new RestRequest(method, DataFormat.Json);

                var response = client.Get(request);

                Employee obj = JsonConvert.DeserializeObject<Employee>(response.Content);

                return obj.Descrip;
            }

What I want is to receive the type Employee or any other as a parameter so the line Employee obj = ... looks like:

type obj = JsonConvert.DeserializeObject<type>(response.Content);

How to send Employee type as parameter to the method CallAPI:
string CallApi("api", "method", Employee)

Employee is a Model in my project.

Thanks in advance.

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,201 questions
{count} votes