> 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)