English 中文(简体)
改变网上设计时间的财产序列顺序
原标题:Change the order of property serialization at design time in .Net
  • 时间:2009-10-21 07:43:02
  •  标签:

I have a class where it s problematic to relay on the properties being serialized in alphabetical order at design time. In other words, property Z must be serialized before property A.

The problem arises because property property Z clears property A whenever it changes - which happens in InitializeComponent. I work around this problem by setting a FirstTime flag, but that seems messy.

我找到了一个解决办法:

处理这一问题的正确方式是什么?

最佳回答

我是“超技能”解决办法的作者。 如果你不喜欢基于<代码>的解决办法。 准则DomSerializer, I thnik , 你的唯一选择是设计你的类别,以便财产可以按任何顺序(无论从哪里都被视为良好做法)。 举例来说,如果是第一次援引其建筑群的话,你是否可以将财产Z不清。 类似:

bool propertyZHasBeenSet=false;
SomeType propertyZ
{
    get {
        //Property getter
    }

    set {
        if(propertyZHasBeenSet) {
            //Clear property A
        } else {
            propertyZHasBeenSet=true;
        }
        //The remaining of the property setter
    }
}

我确信,必须找到更好的方式来完成同样的事情,但你们会这样做。

问题回答

这里的最佳做法是重修你的类别,以便所有设计时间的特性彼此独立。 这正是所有微软可使用的设计型工作。

以前,我几乎多次陷入这一陷阱,我总是通过仅仅在时间,而不是设计时间,使相互独立的棘手问题得到解决。





相关问题
热门标签