Click here to Skip to main content
15,920,111 members
Home / Discussions / C#
   

C#

 
GeneralRe: Serialization in C# Pin
Stephane David15-Jul-03 4:33
Stephane David15-Jul-03 4:33 
GeneralRe: Serialization in C# Pin
Nathan Blomquist15-Jul-03 9:55
Nathan Blomquist15-Jul-03 9:55 
Stephane David wrote:
class CPoint<br />
{<br />
int X;<br />
int Y;<br />
}


First: This little class is unneeded; check out System.Drawing.Point.

Second: You then need to mark your classes with Serializable attributes.

[Serializable(true)]
class CShape
{
string name;
virtual void Draw();
}

[Serializable(true)]
class CCircle : CShape
{
int Radius;
CPoint center;
override void Draw();
}

[Serializable(true)]
class CPolygon : CShape
{
CPoint[] geometry;
override void Draw();
}

[Serializable(true)]
class CDrawing
{
public CShape[] shapes;
}

// functions for saving and loading

using System.Runtime.Serialization.Formatters.Binary;
using System.IO;

void SaveToFile(string path,CDrawing drawing)
{
  using(FileStream fs = File.OpenWrite(path))
  {
     BinaryFormatter bf = new BinaryFormatter();
     bf.Serialize(fs,drawing);
  }
}

CDrawing LoadFromFile(string path)
{
  using(FileStream fs = File.OpenRead(path))
  {
     BinaryFormatter bf = new BinaryFormatter();
     return (CDrawing)bf.Deserialize(fs);
  }
}


Hope this gets you on your way...

-Nathan

---------------------------
Hmmm... what's a signature?
GeneralRe: Serialization in C# Pin
Anonymous16-Jul-03 6:03
Anonymous16-Jul-03 6:03 
GeneralMSMQ Question Pin
ripsi14-Jul-03 19:55
ripsi14-Jul-03 19:55 
Generalhelp me, how to autoscroll in richtextbox Pin
KETUINHA14-Jul-03 17:31
KETUINHA14-Jul-03 17:31 
GeneralRe: help me, how to autoscroll in richtextbox Pin
J. Dunlap14-Jul-03 19:06
J. Dunlap14-Jul-03 19:06 
GeneralRe: help me, how to autoscroll in richtextbox Pin
KETUINHA14-Jul-03 20:49
KETUINHA14-Jul-03 20:49 
GeneralRe: help me, how to autoscroll in richtextbox Pin
J. Dunlap14-Jul-03 21:05
J. Dunlap14-Jul-03 21:05 
GeneralRe: help me, how to autoscroll in richtextbox Pin
KETUINHA14-Jul-03 21:16
KETUINHA14-Jul-03 21:16 
GeneralRe: help me, how to autoscroll in richtextbox Pin
dynamic14-Jul-03 21:29
dynamic14-Jul-03 21:29 
GeneralRe: help me, how to autoscroll in richtextbox Pin
J. Dunlap14-Jul-03 21:45
J. Dunlap14-Jul-03 21:45 
GeneralRe: help me, how to autoscroll in richtextbox Pin
dynamic14-Jul-03 22:00
dynamic14-Jul-03 22:00 
GeneralRe: help me, how to autoscroll in richtextbox Pin
KETUINHA14-Jul-03 22:54
KETUINHA14-Jul-03 22:54 
GeneralProperty values from loaded process Pin
Shaun Becker14-Jul-03 15:39
Shaun Becker14-Jul-03 15:39 
GeneralRe: Property values from loaded process Pin
Rocky Moore14-Jul-03 23:29
Rocky Moore14-Jul-03 23:29 
GeneralRe: Property values from loaded process Pin
Shaun Becker15-Jul-03 0:34
Shaun Becker15-Jul-03 0:34 
GeneralRe: Property values from loaded process Pin
Rocky Moore15-Jul-03 2:48
Rocky Moore15-Jul-03 2:48 
GeneralRe: Property values from loaded process Pin
Shaun Becker15-Jul-03 3:46
Shaun Becker15-Jul-03 3:46 
GeneralRe: Property values from loaded process Pin
Rocky Moore15-Jul-03 13:18
Rocky Moore15-Jul-03 13:18 
GeneralRe: Property values from loaded process Pin
Shaun Becker15-Jul-03 15:00
Shaun Becker15-Jul-03 15:00 
QuestionNon-threaded WebRequest? Pin
Arun Bhalla14-Jul-03 14:38
Arun Bhalla14-Jul-03 14:38 
AnswerRe: Non-threaded WebRequest? Pin
Arun Bhalla15-Jul-03 15:51
Arun Bhalla15-Jul-03 15:51 
Generalcreating a dialoge box in c# Pin
Asim N.14-Jul-03 14:37
Asim N.14-Jul-03 14:37 
GeneralRe: creating a dialoge box in c# Pin
Jim Stewart14-Jul-03 15:11
Jim Stewart14-Jul-03 15:11 
GeneralRe: creating a dialoge box in c# Pin
Member 7681715-Jul-03 12:41
Member 7681715-Jul-03 12:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.