|
-
Jan 15th, 2009, 09:25 AM
#1
Thread Starter
Frenzied Member
[RESOLVED] [2008] XMLSerializer type serialization issue
I'm trying to serialize a user's preferences by means of an XMLSerializer. The preferences class contains Strings, Integers, Booleans and several Color structure variables. The serialization doesn't throw any errors, however the generated xml file has empty values only for the color variables.
I tried the following two declarations of the XMLSerializer object, neither workerd.
Code:
Dim xml As New Xml.Serialization.XmlSerializer(GetType(UsrPreferences), New System.Type() {GetType(Color)})
Dim xml As New Xml.Serialization.XmlSerializer(GetType(UsrPreferences), New Xml.Serialization.XmlRootAttribute("UsrPreferences"))
How can I fix this?
Please rate helpful ppl's posts. It's the best 'thank you' you can give 
-
Jan 15th, 2009, 09:32 AM
#2
Re: [2008] XMLSerializer type serialization issue
Perhaps it isn't serializable or if it is, it isn't dealt with properly.
http://msdn.microsoft.com/en-us/library/ms731923.aspx
You can create, say, a 'wrapper' class which stores the RGB values and get your client app to convert the color back to a proper Color.
-
Jan 15th, 2009, 09:44 AM
#3
Re: [2008] XMLSerializer type serialization issue
Do you have to do XML? There are a variety of things that are not serializable with XML, as Mendhak suggested, though the color structure seems like it should be. If you aren't tied to XML serialization, binary serialization works on more types (including generics), and is easy to use.
My usual boring signature: Nothing
 
-
Jan 15th, 2009, 10:34 AM
#4
Thread Starter
Frenzied Member
Re: [2008] XMLSerializer type serialization issue
I know the limitations of XML serialization, but I've gone too far to abandon it now. Besides, I prefer XML over binary.
I've thought of using a wrapper however I'd prefer to use the Color structure as is and I would only consider it as a last resort.
EDIT: I just remembered what is causing this problem. Apparently, you cannot set the A, R, G and B properties of a color manually since they are ReadOnly. The XMLSerializer will only save non-ReadOnly properties and public fields. I guess the wrapper is the only way. I'm sorry I bothered you.
Please rate helpful ppl's posts. It's the best 'thank you' you can give 
-
Jan 15th, 2009, 10:57 AM
#5
Re: [RESOLVED] [2008] XMLSerializer type serialization issue
You can't set it directly but you can use a method, the name of which is vague to me, called FromARgb which returns a Color.
-
Jan 15th, 2009, 11:14 AM
#6
Thread Starter
Frenzied Member
Re: [RESOLVED] [2008] XMLSerializer type serialization issue
I know that but the XMLSerializer cannot use that method, it sets values directly. That's why it ignores all ReadOnly properties.
Btw, the ARGB part stands for Alpha-Red-Green-Blue, where Alpha is the opacity of the color. Have a look:
http://en.wikipedia.org/wiki/Alpha_compositing
Please rate helpful ppl's posts. It's the best 'thank you' you can give 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|