【问题标题】:Problem with serialization order (designer code) in .NET VS win form project.NET VS win表单项目中的序列化顺序(设计器代码)问题
【发布时间】:2021-02-19 18:39:40
【问题描述】:

据我的另一个question

我有一个列表和一个选定的索引,我序列化:

public interface IControlListManager
{
    List<ControlListManager.TargetSettings> TargetList { get; set; }
    int SelectedIndex { get; set; }
}

在designer.cs里面我得到了下面的序列化代码:

//...
controlListManager1.SelectedIndex = 0;
controlListManager1.TargetList.Add(new ControlListManager.TargetSettings(this, "", DisplayModes.FollowXY, true, 0, 0, 0));
controlListManager1.TargetList.Add(new ControlListManager.TargetSettings(this.InfoPanel, "", DisplayModes.FollowXY, true, 0, 0, 0));
controlListManager1.TargetList.Add(new ControlListManager.TargetSettings(this.InfoText, "", DisplayModes.FollowXY, true, 0, 0, 0));
controlListManager1.TargetList.Add(new ControlListManager.TargetSettings(this.HLine, "", DisplayModes.FollowXY, true, 0, 0, 0));
controlListManager1.TargetList.Add(new ControlListManager.TargetSettings(this.LogiDevType, "", DisplayModes.FollowXY, true, 0, 0, 0));
controlListManager1.TargetList.Add(new ControlListManager.TargetSettings(this.LogiDevSetBtn, "", DisplayModes.FollowXY, true, 0, 0, 0));
controlListManager1.TargetList.Add(new ControlListManager.TargetSettings(this.SystrayContextMenu, "", DisplayModes.FollowXY, true, 0, 0, 0));
controlListManager1.TargetList.Add(new ControlListManager.TargetSettings(this.restoreToolStripMenuItem, "", DisplayModes.FollowXY, true, 0, 0, 0));
controlListManager1.TargetList.Add(new ControlListManager.TargetSettings(this.exitToolStripMenuItem, "", DisplayModes.FollowXY, true, 0, 0, 0));
controlListManager1.TargetList.Add(new ControlListManager.TargetSettings(this.panel1, "", DisplayModes.FollowXY, true, 0, 0, 0));
controlListManager1.TargetList.Add(new ControlListManager.TargetSettings(this.IdentifierInput, "", DisplayModes.FollowXY, true, 0, 0, 0));
controlListManager1.TargetList.Add(new ControlListManager.TargetSettings(this.ExitButton, "", DisplayModes.FollowXY, true, 0, 0, 0));
controlListManager1.TargetList.Add(new ControlListManager.TargetSettings(this.IdentifierCheckbox, "", DisplayModes.FollowXY, true, 0, 0, 0));
controlListManager1.TargetList.Add(new ControlListManager.TargetSettings(this.SaveLogFile, "", DisplayModes.FollowXY, true, 0, 0, 0));
//...

问题是SelectedIndex 应该在列表之后,因为它很好地代表了列表的索引。

如何告诉设计师把它放在列表后面?

【问题讨论】:

标签: c# visual-studio winforms visual-studio-2010 serialization


【解决方案1】:

因为我不想弄乱 BeginInit() 和 EndInit() 方法(我真正应该这样做),并发现,序列化程序的顺序是按字母顺序排列的,这确实是事实。

我将SelectedIndex 重命名为ZSelectedIndex。有趣又肮脏 - 但快速的解决方案。

【讨论】:

    猜你喜欢
    • 2010-09-08
    • 1970-01-01
    • 2020-10-12
    • 1970-01-01
    • 2011-01-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-20
    相关资源
    最近更新 更多