473,320 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Deserialization of boolean values

I have a serializable class containing several bool fields. An XML string
sent to me by another application contains "T" for true and "F" for false.
XMLSerializer uses internally XMLConvert.ToBoolean(). "T" and "F" are not
valid strings for boolean values.
Only "1", "0", "true" and "false" are valid, so I get an exception.

Is there a way to override this behavior and process "T" and "F" normally?
Thank you.

Mike
(prepend my email address with the first letter of my last name)
Nov 12 '05 #1
1 5759
> Only "1", "0", "true" and "false" are valid, so I get an exception.
Right.
What you can do is use a surrogate ("Virtual") property in your type to
gather the value of the boolean, and set the actual field or property. Like
this:

[XmlIgnore] // XmlIgnore == do not serialize or de-serialize this
field
public bool Bool1;

[XmlElement("Bool1")] // aha, but wait! If there is an Element
"Bool1" and it has the value "T", then set Bool1 to true.
public string Bool1_Surrogate {
get { return (Bool1)? "T":"F"; }
set { Bool1= (value=="T"); }
}

full example:
http://cheeso.members.winisp.net/src...e=Surrogate.cs
-Dino

--
Dino Chiesa
Microsoft Developer Division
d i n o c h @ OmitThis . m i c r o s o f t . c o m

"Mike R" <ei***@eskimo.com> wrote in message
news:cu**********@eskinews.eskimo.com...
I have a serializable class containing several bool fields. An XML string
sent to me by another application contains "T" for true and "F" for false.
XMLSerializer uses internally XMLConvert.ToBoolean(). "T" and "F" are not
valid strings for boolean values.
Only "1", "0", "true" and "false" are valid, so I get an exception.

Is there a way to override this behavior and process "T" and "F" normally?
Thank you.

Mike
(prepend my email address with the first letter of my last name)

Nov 12 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: TEK | last post by:
There seems to be a bug when deserialization some classes in the .NET framework. If you try to deserialize a class that has a base class that holds a struct with a member that is implementing...
1
by: AA | last post by:
I want to Deserialize this simple xml... ==================================================================== <SubmitReq...
5
by: Urs Vogel | last post by:
Hi I'm wondering if there's a technique to deserialize objects which were serialized with an earlier version of the class. Example: // version 1 class { string myString; int ...
3
by: Brad King | last post by:
I'm calling an Axis web service (from a .Net client) that returns an array of a complex type. The complex type wrapper appears to have been generated with all members intact from the wsdl using...
3
by: parrot toes | last post by:
Summary: I have been trying to make requests of a web service provided by Axis using a dotnet client with code generated by wsdl.exe and have been getting exceptions when trying to process the...
1
by: parrot toes | last post by:
I tried to post this question before, but there was an error when posting. I case it did get posted and in order to avoid duplication, I'll just repost a summary. I have written a dotnet client...
0
by: Wes Shaddix | last post by:
I have a vendor web service that I have created a web application to interact with. The service works fine in VS 2003 but fails in VS 2005. I have implemented a proxy between the web client and...
5
by: Greg Allen | last post by:
I am consuming a web service and using the generated Reference.cs to access the service and the objects associated with it. I have run into a problem where some inherited classes are not being...
6
by: Joe | last post by:
I'm getting an error when deserializing my objects: "The ObjectManager found an invalid number of fixups. This usually indicates a problem in the Formatter." I added a new object to a class that...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.