G
Guest
I have a class, "MySavableClass." The class has one string property named
"MyID" and then a bunch of other properties.
Ideally, what I'd like to do is write a "Save()" and a "Restore()" method -
or probably static methods for this object that would work as follows:
private MySavableClass MyC = new MySavableClass();
MyC.MyID = "Class1";
MyC.SomeOtherProperty = 1234;
//The next line will cause the class "MyC" to be serialized and then written
//to a two column database tabe. Column 1 will be the ID column which,
//in this case, will be "Class1", and column 2 will be a Text/Memo column
//which will take the entire serialized object.
Success = MySavableClass.Save(MyC);
//Later, I should be able to do this...
private MySavableClass MyCRestored;
MyCRestored = MySavableClass.Restore("Class1");
if(MyCRestored == null)
//Restoration failed!
else
Writeln("MyCRestored.SomeOtherProperty = " +
MyCRestored.SomeOtherProperty.ToString());
etc., etc.
All of this doesn't seem that hard but I have a few questions:
1. Do I have to set up any meta-tagging on my calss to make it serializable
(it's a pretty simple class.
2. Which serialization method should I use if I want to save the data as
text to a database column?
Any other guidance you can provide will be much appreciated.
Alex
"MyID" and then a bunch of other properties.
Ideally, what I'd like to do is write a "Save()" and a "Restore()" method -
or probably static methods for this object that would work as follows:
private MySavableClass MyC = new MySavableClass();
MyC.MyID = "Class1";
MyC.SomeOtherProperty = 1234;
//The next line will cause the class "MyC" to be serialized and then written
//to a two column database tabe. Column 1 will be the ID column which,
//in this case, will be "Class1", and column 2 will be a Text/Memo column
//which will take the entire serialized object.
Success = MySavableClass.Save(MyC);
//Later, I should be able to do this...
private MySavableClass MyCRestored;
MyCRestored = MySavableClass.Restore("Class1");
if(MyCRestored == null)
//Restoration failed!
else
Writeln("MyCRestored.SomeOtherProperty = " +
MyCRestored.SomeOtherProperty.ToString());
etc., etc.
All of this doesn't seem that hard but I have a few questions:
1. Do I have to set up any meta-tagging on my calss to make it serializable
(it's a pretty simple class.
2. Which serialization method should I use if I want to save the data as
text to a database column?
Any other guidance you can provide will be much appreciated.
Alex