Writing pens to file

T

Tristan

Hi,

In my application I need to store pen objects in a file so they can be
read in at a latter stage from the file to recreate the pen objects in
memory. I'm currently doing this by hand, blindly writing out all the
properties of a pen like a donkey! Surely there must be a neat way in
..NET to read and write such objects? I don't want to simply serialize
the object as that would include a lot of stuff in the file I'm not
interested in. In the future I need to do a similar thing for brushes.

The code below shows how I write and read the compound array property
of a pen:

// Write pen's Compound array
int compLength = edgePens.CompoundArray.Length;
binaryWriter.Write(compLength);
for (int j = 0; j < compLength; j++)
{
binaryWriter.Write((double)edgePens.CompoundArray[j]);
}

// Read Pen's Compound array
int compLength = binaryReader.ReadInt32();
float compArray = new float[compLength]
for (int j = 0; j < compLength; j++)
{
compArray[j] = (float)binaryReader.ReadDouble()
}


Which as you can see, is a bit ugly when you have to do this kind of
thing for all the pen's properties!

Any help much appreciated.

Tristan.
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi Tristan,

I think that it's the only way of doing it, as the Pen class does not
support serialization ( nor you want it ).
I think that the best way of doing this, is saving only those properties
that you change in your code. I don't see other solution here :(

Cheers,
 

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