Click here to Skip to main content
15,913,773 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted

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
 
Share this answer
 
v2
Comments
Kim Togo 12-May-11 5:06am    
Good answer.
Sergey Alexandrovich Kryukov 12-May-11 12:26pm    
Thank you, Kim.
--SA
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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900