当我点击下面一行代码时出现错误:
using (_client = new RestClient("url", this))
错误:“MyNamespace.RestClient(MyNamespace.MyPresenter,string)”的最佳重载方法匹配具有一些无效参数
我看过一百万个“最好的重载方法匹配”线程,但我的问题似乎有所不同。详细的编译器输出表明它无法转换为:
MyPresenter [C:\ path \ to \ class \ file] to MyPresenter [C:\ Windows \ Microsoft.NET \ Framework64 \ v4.0.30319 \ Temporary ASP.NET Files \ root \ 3d988ef4 \ 66e82b30 \ assembly \ dl3 \ 995d0d63 \ 042c184e_aae2cf01 \ ProjectName.DLL]
我不确定这里出了什么问题。类型是相同的。
这是我的完整代码(ASP.net中的MVP模式):
// default.aspx.cs (View class)
public partial class MyView : Page
{
private readonly MyPresenter _presenter;
public MyView()
{
_presenter = new MyPresenter(this);
}
public TextBox OutputText
{
get { return outputText; }
}
protected void Page_Load(object sender, EventArgs e) {}
protected void GoButton_OnClick(object sender, EventArgs eventArgs)
{
_presenter.DoStuff();
}
}
// default.aspx.designer.cs
public partial class MyView
{
protected global::System.Web.UI.WebControls.Button goButton;
protected global::System.Web.UI.WebControls.TextBox outputText;
}
// MyPresenter.cs
public class MyPresenter
{
private RestClient _client;
public MyPresenter(MyView view)
{
View = view;
}
public MyView View { get; private set; }
public void DoStuff()
{
**using (_client = new RestClient("url", this))** // Error here
{
_client.DoClientStuff()
}
}
}
// RestClient.cs
public class RestClient
{
private readonly MyPresenter _presenter;
private readonly string _url;
public RestClient(string url, MyPresenter presenter)
{
_presenter = presenter;
_url = url;
}
public void DoClientStuff()
{
_presenter.View.OutputText.Text = "Doing client stuff";
}
}
答案 0 :(得分:0)
你的参数倒退了
using (_client = new RestClient("url", this))
应该是
using (_client = new RestClient(this, "url"))