What are you using to process the data? Since that is obviously custom serialization, it seems like you should be able to tweak "BooleanField" processing to handle both...
IMO, though, your not using xml the way it is intended... it would be easier to specify this as elements/attributes, like how XmlSerializer
would (indeed - why not just use XmlSerializer
?):
<isActive>true</isActive>
or
<foo ... isActive="true" ... />
Note that the xml standard for true/false is lower case...
Additionally; if you are using TypeConverter
- you can just change the converter:
using System;
using System.Collections.Generic;
using System.ComponentModel;
public class Program
{
static void Main()
{
TypeDescriptor.AddAttributes(typeof(bool),
new TypeConverterAttribute(typeof(MyBooleanConverter)));
TypeConverter conv = TypeDescriptor.GetConverter(typeof(bool));
Console.WriteLine((bool)conv.ConvertFrom("True"));
Console.WriteLine((bool)conv.ConvertFrom("true"));
Console.WriteLine((bool)conv.ConvertFrom("False"));
Console.WriteLine((bool)conv.ConvertFrom("false"));
Console.WriteLine((bool)conv.ConvertFrom("0"));
Console.WriteLine((bool)conv.ConvertFrom("1"));
}
}
class MyBooleanConverter : BooleanConverter
{
static readonly Dictionary<string, bool> map
= new Dictionary<string, bool>(StringComparer.OrdinalIgnoreCase)
{ { "true", true }, { "false", false },
{ "1", true }, { "0", false } };
public override object ConvertFrom(ITypeDescriptorContext context,
System.Globalization.CultureInfo culture, object value)
{
string s = value as string;
bool result;
if (!string.IsNullOrEmpty(s) && map.TryGetValue(s, out result))
{
return result;
}
return base.ConvertFrom(context, culture, value);
}
}