Serialization of controls

J

John Sutor

Does anyone have a good example of how to serialize a controls
properties?
HEre is my example but is does not work

object mObject = this.textBox1;
Debug.WriteLine(mObject.GetType());
XmlSerializer formatter = new XmlSerializer(mObject.GetType());
Stream stream = new FileStream("serialTest.xml",FileMode.Create,
FileAccess.Write,FileShare.None);
formatter.Serialize(stream,mObject);
stream.Close();

John S
 
N

Nicholas Paldino [.NET/C# MVP]

John,

The problem with the XmlSerializer is that it will only save public
properties, and a good number of those properties are other classes that
when serialized, really don't have the correct context. Ultimately, you
can't serialize everything, because things such as a control handle have no
context.

What I would do is create an object that implements
ISerializationSurrogate, so that you can provide serialization semantics
without having to implement it on the control. This way, you can specify
the properties you want to save, and not have to create different classes
which implement ISerializable.

Hope this helps.
 
J

John Sutor

Nicholas,
I was just trying to figure out how serialization works.
I wanted to create a simple example of using serialization for
something.
If you have a simple sample, I'd be grateful

Thanks,

John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top