The process you're describing is called serialization/deserialization. .NET
could serialize object as a binary or XML stream.
Unfortunately CF currently doesn't support that, but you can either roll out
your own custom serialization or use the XML serialization implemented in
SDF:
http://www.opennetcf.org/PermaLink.aspx?guid=3a013afd-791e-45ef-802a-4c1dbe1
cfef9
Here is the simple sample on how you could write your own serialization:
class Employee
{
string name;
string address;
public Employee(string name, string address)
{
this.name = name;
this.address = address;
}
public Employee(BinaryReader reader)
{
name = reader.ReadString();
address = reader.ReadString();
}
public string Name
{
get
{
return name;
}
}
public string Address
{
get
{
return address;
}
}
public void Save(BinaryWriter writer)
{
writer.Write(name);
writer.Write(address);
}
}
HTH... Alex
--
Alex Yakhnin .NET CF MVP
www.intelliprog.com |
www.opennetcf.org
stevebju said:
I'm having the hardest time reading and writing a simple class object to
and from a file in the CF. Could someone show me how to write a class object
to a file? Then if I have multiple objects in a file, how do I read them out
one by one?