Serialization in C# (Newbie)

R

RKS

I have a question regarding serialization. Although there are many
articles regarding this, I am still a little confused. I know that to
make a class serializable, I need to add a [Serialize] attribute. But
where should I add my serialize and deserialize code. I mean like
specifying the type of formatter and filename etc. I am used to
programming in Visual C++/MFC. Serialize (storing) is called in onSave
and Serialize (loading) gets called in onNew or onOpen.
Thanks for any help.
 
S

simida

I think you can find more information about xml serialization in the
System.Xml.Serialization namespace.

For example, P.Program object has serializable attribute. Now, you can
use it as follows,

public static void SerializeMetaData(P.Program program, StreamWriter
streamWriter)
{
XmlSerializer serializer = new XmlSerializer(typeof(P.Program));
serializer.Serialize(streamWriter, program);
}

This is just a simple demo about xml serialization. Moreover, you will
be able to control which class' flied serialized or un-serialized.Plz
check System.Xml.Serialization namespace.

Sincerely,
simida
 
R

RKS

simida said:
I think you can find more information about xml serialization in the
System.Xml.Serialization namespace.

For example, P.Program object has serializable attribute. Now, you can
use it as follows,

public static void SerializeMetaData(P.Program program, StreamWriter
streamWriter)
{
XmlSerializer serializer = new XmlSerializer(typeof(P.Program));
serializer.Serialize(streamWriter, program);
}

This is just a simple demo about xml serialization. Moreover, you will
be able to control which class' flied serialized or un-serialized.Plz
check System.Xml.Serialization namespace.

Sincerely,
simida

Thankyou Simida. I will try your suggestion.
Ramesh.K.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top