将字符串转换为RestSharp定义的调用方法

问题描述

因此,我尝试使用RestSharp并创建一个处理所有内容函数,然后单独调用它,而不是每次都在restsharp中使用每个函数。 我遇到的麻烦是将String参数用作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**);
    }

这是个好方法吗?

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

解决方法

这有效:

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