0

I was using the sample code specified in the link below to convert the xml value which is a string "Y" into a boolean value for the property it is mapped against. However in my xml that is being serialized the xml element may not exist but I still want to map it to a property in my object. Curently after serialization this property has a null value but I want to set it to false. How can I do this using the example in the link below.

I did try this by setting it in the constructor for the property but then I get an error. Cannot implicitly convert type 'bool' to 'BoolYN'

XmlSerializer property converter

Community
  • 1
  • 1
user1334589
  • 117
  • 1
  • 2
  • 9

1 Answers1

0

If I understand you, you should implement IXmlSerializable

http://msdn.microsoft.com/pl-pl/library/system.xml.serialization.ixmlserializable%28v=vs.110%29.aspx

And write your own interpretation of "Y" to bool and use [XmlIgnore] for "unused" property.

Rayet
  • 298
  • 1
  • 11