Why are System.Windows.Forms.Control not marked as serializable?

前端 未结 3 1996
星月不相逢
星月不相逢 2020-12-21 16:18

I am not able to deep copy UserControls because they are not marked as serializable.

What is the reason behind this design?

3条回答
  •  执笔经年
    2020-12-21 17:11

    Usercontrols are a visual element, and as such why would you ever want to serialize them? You are never going to send them across a WCF service, or stream them to a data repository. If you need to transmit or store usercontrols then you would store their key properties and recreate them where necessary.

    Instead of using serialization to create a clone, go back to using a more traditional method like manually copying specific properties on known types, or use reflection.

提交回复
热议问题