Alex Toma
Alex Toma

Reputation: 101

Convert string to a RestSharp defined call method

So I'm trying to use RestSharp and create a function that handles everything and then call it alone, instead of using every single function in restsharp everytime. What I'm having trouble with is having a String parameter be used as a definition inside Method of RestRequest.

    public void GetRestClient(string country, string method, string endpoint, string body = null) 
    {
        string url = getCountryUrl(country) + endpoint;
        RestClient client = new RestClient(url);
        RestRequest getRequest = new RestRequest(Method.**method**);
    }

Would this be a good way?

        RestRequest getRequest = new RestRequest((Method)Enum.Parse(typeof(Method), method));

Upvotes: 1

Views: 1197

Answers (1)

Alex Toma
Alex Toma

Reputation: 101

This worked:

 RestRequest getRequest = new RestRequest((Method)Enum.Parse(typeof(Method), method));

Upvotes: 1

Related Questions