Serialization of controls

  • Thread starter Thread starter John Sutor
  • Start date Start date
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
 
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.
 
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
 
Back
Top