解析布尔C#Culture verdadero
我正试着运行这条线路,但它不起作用。有人知道原因吗解析布尔C#Culture verdadero,c#,xml-parsing,boolean,cultureinfo,C#,Xml Parsing,Boolean,Cultureinfo,我正试着运行这条线路,但它不起作用。有人知道原因吗 Convert.ToBoolean("verdadero", new System.Globalization.CultureInfo("ES-MX")); 我从一个安装了多种语言的程序生成的xml文件中解析它,因此它在“EN-US”区域中使用“true”,在“ES-MX”中使用“verdadero”。很有趣。通过反编译器运行Convert.ToBoolean会发出以下信息: /// <summary> /// Converts
Convert.ToBoolean("verdadero", new System.Globalization.CultureInfo("ES-MX"));
我从一个安装了多种语言的程序生成的xml文件中解析它,因此它在“EN-US”区域中使用“true”,在“ES-MX”中使用“verdadero”。很有趣。通过反编译器运行Convert.ToBoolean会发出以下信息:
/// <summary>
/// Converts the specified string representation of a logical value to its Boolean equivalent, using the specified culture-specific formatting information.
/// </summary>
///
/// <returns>
/// true if <paramref name="value"/> equals <see cref="F:System.Boolean.TrueString"/>, or false if <paramref name="value"/> equals <see cref="F:System.Boolean.FalseString"/> or null.
/// </returns>
/// <param name="value">A string that contains the value of either <see cref="F:System.Boolean.TrueString"/> or <see cref="F:System.Boolean.FalseString"/>. </param><param name="provider">An object that supplies culture-specific formatting information. This parameter is ignored.</param><exception cref="T:System.FormatException"><paramref name="value"/> is not equal to <see cref="F:System.Boolean.TrueString"/> or <see cref="F:System.Boolean.FalseString"/>. </exception><filterpriority>1</filterpriority>
[__DynamicallyInvokable]
public static bool ToBoolean(string value, IFormatProvider provider)
{
if (value == null)
return false;
else
return bool.Parse(value);
}
//
///使用指定的区域性特定格式信息,将逻辑值的指定字符串表示形式转换为其等效布尔值。
///
///
///
///如果等于,则为true;如果等于或为null,则为false。
///
///包含或值的字符串。提供区域性特定格式信息的对象。忽略此参数。不等于或。1.
[[uuuu动态调用可禁用]
公共静态bool ToBoolean(字符串值,IFormatProvider提供程序)
{
如果(值==null)
返回false;
其他的
返回bool.Parse(值);
}
这使得IFormatProvider看起来完全被忽略了
我很想说这是框架中的一个缺陷,但经验告诉我,当我得出这个结论时,我通常会遗漏一些东西…与论坛网站不同,我们不使用“感谢”或“感谢任何帮助”或签名。请参阅“.XML文档是否有XML模式(例如XSD文件)或其他规范?如果有,它应该枚举所有可能的值。不幸的是,我没有看到任何好的选项。