Sahil Malik said:
It's easy, implement ISerializable. it'll add the GetObjectData. Then
just
do info.AddValue("..","..") .. nothing special just because it's a
dataset.
Thanks, I'll give it a try.
But coming back to my main point, simply putting the attribute
[Serializable] should work as long as you don't use non-serializable
member
variables
It really doesn't, though. Honestly. The following code (at least in
Framework 1.1) will throw a SerializationException: "The constructor to
deserialize an object of type ConsoleApplication1.XDataSet was not found."
#region Using directives
using System;
using System.Collections;
using System.Data;
using System.Runtime.Serialization.Formatters.Soap ;
using System.IO ;
#endregion
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
SoapFormatter sf = new SoapFormatter();
FileStream fs = new FileStream("data.xml", FileMode.Create);
XDataSet ds = new XDataSet() ;
sf.Serialize(fs, ds);
fs.Close();
//Empties obj.
ds = null;
//Opens file "data.xml" and deserializes the object from it.
fs = File.Open("data.xml", FileMode.Open);
sf = new SoapFormatter();
ds = (XDataSet)sf.Deserialize(fs);
fs.Close();
}
}
[Serializable]
public class XDataSet : DataSet
{
private ArrayList list;
public XDataSet()
{
DataTable dt = new DataTable("X");
this.Tables.Add(dt);
dt.Columns.Add("X1", typeof(int));
dt.Columns.Add("X2", typeof(string));
list = new ArrayList();
}
public ArrayList List
{
get { return list; }
}
}
}