I\'m having an issue with deserializing an XML file with boolean values. The source XML files I\'m deserializing were created from a VB6 app, where all boolean values are c
I have an xml with many booleans and I didn't want to end up having so many duplicate boolean properties, so I tried a different approach of providing a custom xml reader to do the work:
public class MyXmlReader : XmlTextReader
{
public MyXmlReader(TextReader reader) : base(reader) { }
public override string ReadElementString()
{
var text = base.ReadElementString();
// bool TryParse accepts case-insensitive 'true' and 'false'
if (bool.TryParse(text, out bool result))
{
text = XmlConvert.ToString(result);
}
return text;
}
}
and use with:
using (var sr = new StringReader(text))
using (var r = new MyXmlReader(sr))
{
var result = serializer.Deserialize(r);
}