陷入下面的问题请帮忙, 我有一个下面的类,它包含一个返回类型为interface
的方法public class Helper
{
public IRestResponse GetCam (string searchTerm, int page, int pageSize)
{
RestRequest request = new RestRequest(Method.GET)
{
RequestFormat = DataFormat.Json,
Resource = string.Format("/assets/campaigns?search={0}&page={1}&count={2}&depth=complete",
searchTerm, page, pageSize)
};
IRestResponse response = _client.Execute(request);
return response;
}
}
在该界面中我有一些设置,
public interface IRestResponse
{
string Content { get; set; }
string ContentEncoding { get; set; }
long ContentLength { get; set; }
string ContentType { get; set; }
IList<RestResponseCookie> Cookies { get; }
Exception ErrorException { get; set; }
string ErrorMessage { get; set; }
IList<Parameter> Headers { get; }
IRestRequest Request { get; set; }
ResponseStatus ResponseStatus { get; set; }
Uri ResponseUri { get; set; }
}
}
现在当我在我的另一个程序中调用Helper类时,它给出了错误:
&#34;无法隐式转换类型&#39; RestSharp.IRestResponse&#39;到&#39; System.Collections.Generic.IList&gt;&#39;。存在显式转换(您是否错过了演员?)&#34;
我的通话程序有以下代码
CamSample.Helper f = new CampaignHelper("Company name", "UserName", "Password", "SiteName");
IList<CampaignSample.Models.IRestResponse> q = new List<CampaignSample.Models.IRestResponse>();
//List<IRestResponse<CampaignSample.Models.Campaign>> w = new IList<IRestResponse<CampaignSample.Models.Campaign>>().ToList();
q = f.GetCam("", 1, 200);
---在这里得到错误 请告诉我解决方案
答案 0 :(得分:2)
你的方法是返回IResponse
对象而不是List<IResponse>
对象,你在调用时应该像这样写:
CampaignSample.Models.IRestResponse response = f.GetCam("", 1, 200);
或者您可以在此处使用var
:
var response = f.GetCam("", 1, 200);