需要.NET控制序列化 [英] Need .NET controls serialization

查看:81
本文介绍了需要.NET控制序列化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,
我需要序列化.NET托管进程的每个控件(无论它的主要形式,子控件如按钮,日历,文本框,列表框和组合等等).每个简单的类对象都可以使用二进制格式化程序轻松地进行序列化/反序列化.但是,这些通过反射(Type.GetFields(),Type.GetProperties()..)获取信息的控件并未通过我描述的这种序列化方法进行任何序列化. 主要是它引发要序列化的System.Forms.Form.WinForm类型"异常.序列化后,我需要将这些控件信息照原样传递给其他远程进程.
任何了解.NET如何控制信息的机构都可以以任何方式进行序列化.杰森呢?
关于Usman

Hello,
I need to serialize every control of .NET managed process(whether its main form, child controls like buttons, calender, text boxes, list boxes and combos etc..). Every simple class object is easily serializeable/deserializeable using binary formatters. But these controls which I got their info through reflection(Type.GetFields(), Type.GetProperties()..) are not serializaing in any way through this serialization method which I described.
Mainly it throws "type System.Forms.Form.WinForm to be serialize" exception. After serialization i need to pass these controls information as it is to other remote process.
Any body having idea how can .NET controls information be serializeable any way. What about Json?
Regards Usman

推荐答案

帮个忙:不要序列化控件.

使用松散耦合.创建数据模型,该模型由代表您的UI配置的一些纯数据类组成.提供您的数据模型与UI之间的转换.序列化模型.最好和最简单的方法是数据合同.它是最少侵入性的工具.它还允许持久保存任意对象图,而不仅仅是树.您只应分别向类/结构及其成员添加属性[DataContract]和[DataMember].

参见:
http://msdn.microsoft.com/en-us/library/ms733127.aspx [ ^ ].

松耦合很重要,需要了解:
http://en.wikipedia.org/wiki/Loose_coupling [ http://msdn.microsoft.com/en-us/library/system. runtime.serialization.datacontractserializer.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/system. runtime.serialization.datacontractattribute.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/system. runtime.serialization.datamemberattribute.aspx [ ^ ].

—SA
Do yourself a favor: do not serialize controls.

Use loose coupling. Create data model, consisting of some pure-data classes representing your UI configuration. Provide translation of you data model from/to UI. Serialize the model. Best and simplest way to do is Data Contract. It is least intrusive, tool. It also allows to persist an arbitrary object graph, not only a tree. You only add attributes [DataContract] and [DataMember] to classes/structures and their members, respectfully.

See:
http://msdn.microsoft.com/en-us/library/ms733127.aspx[^].

Loose coupling is important to understand:
http://en.wikipedia.org/wiki/Loose_coupling[^].

See also:
http://msdn.microsoft.com/en-us/library/system.runtime.serialization.datacontractserializer.aspx[^],
http://msdn.microsoft.com/en-us/library/system.runtime.serialization.datacontractattribute.aspx[^],
http://msdn.microsoft.com/en-us/library/system.runtime.serialization.datamemberattribute.aspx[^].

—SA


是的.

我们需要自定义对象,这些对象会将具有.NET"FieldInfo"反射结构的UI转换为我们的自定义结构.此结构的每个逐位字段都应包含在该自定义对象中.每个自定义对象也应以相同的方式在该对象中以适当的位置表示.此外,所有这些结构也将被标记为[DataContract]和[DataMember].

为了将FieldInfo数据序列化或传输到上层,必须存在FieldInfo结构到我们相应结构的精确副本.

这就是你在说什么吗??

问候
乌斯曼
Yeah.

We need custom objects that will translate our UI having .NET "FieldInfo" reflection structure to our custom structure. Every bit by bit field of this structure should contain in that custom object. Every custom object should be represented in the same manner in that object with appropriate position as well. Further all of those structures will be marked as [DataContract] and [DataMember] to classes as well.

Exact replica of FieldInfo structure to our corresponding structure must be present in order to serialize or transfer FieldInfo data to upper layers.

Is this is what you are talking about.?

Regards
Usman


这篇关于需要.NET控制序列化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆