Home
Virtual Image Printer DriverMiraplacid Publisher converts documents to images
Virtual Text Printer DriverMiraplacid Text Driver extracts text from documents
Miraplacid Data ViewerMiraplacid Data Viewer - access to internal structure of a binary file
Miraplacid Text ViewerMiraplacid Text Viewer - access to internal structure of a text file
Common:   Login | Rules of forum | Register
Management:  New topic | Close topic | Move topic | Delete topic
  

Miraplacid Forum >> Software Development >> XmlSerializer does not serialize ColorModerator:XMan

Author Topic:  XmlSerializer does not serialize Color
jn
Member

From: Norway
Email
posted 2004-04-03 03:09:55 Reply -Delete

XmlSerializer serializes class with primitive elements pretty good, but for some reason
it does not serilize Color despite the fact that Color is a structure.
Is it bug or feature? Is there a workaround or something?

Barbara
Member

From: AU
posted 2004-04-03 06:21:18 Reply -Delete

I assume you mean XmlSerialize in DotNet.
As far as I understood, XmlSerializer can work only with public read/write properties.
In Color R,G,B and A in Color are read-only, so serializer cannot restore them from XML file.
In fact, XmlSerialize does not even try to save them.
You have 3 options.
1. Use KnownColor instead of Color.
2. If you have non-standard colors, save R,G,B and A for every color or make your own structure
with public R,G,B and A.
3. Write custom serialization function.

jn
Member

From: Norway
Email
posted 2004-04-03 07:17:31 Reply -Delete

Thanks a lot!
BTW, Rectangle looks in XML like

55
4040

5
5
40
40


Isn't is weird? Whould I modify both X-es to move it?

jn
Member

From: Norway
Email
posted 2004-04-03 07:18:29 Reply -Delete

oops, I mean
Thanks a lot!
BTW, Rectangle looks in XML like
<Rectangle>
<Location><X>5</X><Y>5</Y></Location>
<Size><Width>40</Width><Height>40</Height>
</Size>
<X>5</X>
<Y>5</Y>
<Width>40</Width>
<Height>40</Height>
</Rectangle>

Isn't is weird? Whould I modify both X-es to move it?

Barbara
Member

From: AU
posted 2004-04-05 02:38:07 Reply -Delete

Look at Rectangle structure.
It has following public properties with read/write access:

X,Y,Width,Height,Location,Size
It is exactly what you see in the XML

Location and Size is just duplicate of X,Y,Width,Height

It seems, the DotNet 1.1 XmlSerialize I use, reads X,Y,Width,Height
and ignores Location and Size

If you prepare XML file manually, you can remove Location and Size.
If you save and load XML file with XmlSerialize, why would you care
as long as it works properly?

jn
Member

From: Norway
Email
posted 2004-04-07 11:52:43 Reply -Delete

Thanks! Got it!

Your message:
Name, password:
Go to category:  

Technical Support

Copyright © Miraplacid, 2003 - 2024