How to get DataMemberAttribute to use boolean type
I have a simple test application that pulls an XML document from a rest interface. A data item has a couple of string fields and a couple of boolean fields. I create a simple entity class and put a DataContractAttribute on it and then add DataMemberAttributes to each data member. Then I use HttpResponseMessage.Content.ReadAsDataContract () to parse the response. All string types go through fine, but all my booleans are false (and they are not really false). The xml element looks something like this:
<is-enabled type="boolean">true</is-enabled>
and then in my type class I have something like:
[DataMember(Name="is-enabled")]
public bool isEnabled
{
get
{
return this.isEnabledField;
}
set
{
this.isEnabledField = value;
}
}
How do I get the correct boolean values?
source to share
It seems like it should work, but ... the first thing I try is to remove the dash "-" from the data member name. It is possible that the serializer (de) loops on the dash inside and does not display the correct member and hence gives you a default bool value of false
If you feel the need to complicate the name of a compound variable, try underlining.
source to share