データの処理には何を使用していますか?これは明らかにカスタムシリアル化なので、両方を処理するために "BooleanField"処理を微調整する必要があるようです...
IMO、あなたは使用していないxmlを意図しています...それはもっと簡単でしょうどのようXmlSerializer
がうような要素/属性、としてこれを指定する(?確かに - なぜちょうどXmlSerializer
を使用しない):真/偽のXML標準は、下ケースであることを
<isActive>true</isActive>
または
<foo ... isActive="true" ... />
を注意...
さらに、 TypeConverter
を使用している場合は、コンバータを変更することができます:
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);
}
}
私は受け取っているxmlを制御できません。ですから、基本的に私は一貫性のないxmlを提供されています。今私はxmlのTrueを探し、それを1に置き換えます。 – chefsmart