开发者

"Illegal characters in path." Visual Studio WinForm Design View

开发者 https://www.devze.com 2022-12-25 07:05 出处:网络
I am putting together a lightweight MVP pattern for a WinForms project.Everything compiles and runs fine.However when I attempt to open the WinForm in design mode in Visual Studio I get a \"Illegal ch

I am putting together a lightweight MVP pattern for a WinForms project. Everything compiles and runs fine. However when I attempt to open the WinForm in design mode in Visual Studio I get a "Illegal characters in path" error. My WinForm is using generics and inheriting from a base Form class. Is there a problem with using generics in a WinForm?

Here is the WinForm and base Form class.

public partial class TapsForm : MvpForm<TapsPresenter, TapsFormModel>, ITapsView
{
    public TapsForm()
    {
        InitializeComponent();
    }

    public TapsForm(TapsPresenter presenter)
        :base(presenter)
    {
        InitializeComponent();
        UpdateModel();
    }

    public IList<Taps> Taps
    {
        set { gridTaps.DataSource = value; }
    }

    private void UpdateModel()
    {
        Model.RideId = Int32.Parse(cboRide.Text开发者_开发百科);
        Model.Latitude = Double.Parse(txtLatitude.Text);
        Model.Longitude = Double.Parse(txtLongitude.Text);
    }
}

Base form MvpForm:

public class MvpForm<TPresenter, TModel> : Form, IView
    where TPresenter : class, IPresenter
    where TModel : class, new()
{
    private readonly TPresenter presenter;
    private TModel model;

    public MvpForm()
    {
    }

    public MvpForm(TPresenter presenter)
    {
        this.presenter = presenter;
        this.presenter.RegisterView(this);
    }

    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
        if (presenter != null)
            presenter.IntializeView();
    }

    public TModel Model
    {
        get 
        {
            if (model == null)
                throw new InvalidOperationException("The Model property is currently null, however it should have been automatically initialized by the presenter. This most likely indicates that no presenter was bound to the control. Check your presenter bindings.");

            return model;
        }
        set { model = value;}
    }
}


This post helped answer my question.

Apparently, this a limitation in Visual Studio. I was able to work around it by having an intermediary class that defined the generic values. It a really ugly work around, but I can now open the form in Visual Studio.

Here is my intermediary class, which has to be either in a seperate file, or AFTER the form class definition. It must also have a default constructor, implicit or explicit:

public class MvpTapsForm : MvpForm<TapsPresenter, TapsFormModel>
{
}

Then in my actual form I inherit from MvpTapsForm.

public partial class TapsForm : MvpTapsForm, ITapsView
{
    public TapsForm()
    {
        InitializeComponent();
    }

    public TapsForm(TapsPresenter presenter)
        : base(presenter)
    {
        InitializeComponent();
        UpdateModel();
    }

    public IList<Taps> Taps
    {
        set { gridTaps.DataSource = value; }
    }

    private void UpdateModel()
    {
        Model.RideId = Int32.Parse(cboRide.Text);
        Model.Latitude = Double.Parse(txtLatitude.Text);
        Model.Longitude = Double.Parse(txtLongitude.Text);
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消