c# - How to serialize/deserialize PictureBox -
[serializable] class gameobject : picturebox { public bool solid; public bool selected; }
is there way serialize backcolor
, size
, location
etc...?
for temporary small type of objects prefer use structures, although can use classes per needs. can serialize , de-serialize objects using these helper methods.
public static string serialize<t>(t objecttoserialize) { xmlserializer xmlserializer = new xmlserializer(typeof(t)); stringwriter textwriter = new stringwriter(); xmlserializer.serialize(textwriter, objecttoserialize); return textwriter.tostring(); } public static t deserialize<t>(string stringtodeserialize) { xmlserializer xmlserializer = new xmlserializer(typeof(t)); stringreader textreader = new stringreader(stringtodeserialize); return (t)xmlserializer.deserialize(textreader); }
how serialize object-to-string:
mystructure myobject = getpictureboxobject(); string pbserializedstring = serialize<mystructure>(myobject);
how deserialize string-to-object:
string str = getstringtodeserialize(); mystructure myobject = deserialize<mystructure>(str);
Comments
Post a Comment