【问题标题】:The best overloaded method match for <type> has some invalid arguments<type> 的最佳重载方法匹配有一些无效参数
【发布时间】:2014-10-08 21:37:41
【问题描述】:

点击以下代码行时出现错误:

using (_client = new RestClient("url", this))

错误: 'MyNamespace.RestClient(MyNamespace.MyPresenter, string)' 的最佳重载方法匹配有一些无效参数

我已经查看了一百万个“最佳重载方法匹配”线程,但我的问题似乎有所不同。详细的编译器输出表明它无法从以下位置转换:

MyPresenter [C:\path\to\class\file] 到 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";
    }
}

【问题讨论】:

  • I can give some more details about my class structure if necessary,更多细节?您向我们提供的相关信息是什么?
  • 你最好的选择在这里SuperFly 是显示一些代码..

标签: c# asp.net webforms mvp


【解决方案1】:

你的参数倒过来了

using (_client = new RestClient("url", this))

应该是

using (_client = new RestClient(this, "url"))

【讨论】:

  • 糟糕,这是一个转录错误。实际代码中并非如此。它现在已在我的帖子中修复。
猜你喜欢
  • 2015-10-14
  • 2018-07-14
  • 2013-01-07
  • 2014-05-17
  • 1970-01-01
  • 2014-04-14
  • 2012-12-10
  • 1970-01-01
相关资源
最近更新 更多