Fxcop:Globlization warning/全球化警告

本小妞迷上赌 提交于 2019-11-26 18:30:06

Fxcop:Globlization warning/全球化警告

 

在如下codesnippet:

    DataTable dt= new DataTable("Customers");
    dt.Columns.Add("ID", typeof(Int32));

    dt.Columns.Add("Name", typeof(string));

    return dt;

会出现警告:Set locale for data types, 经查MSDN得知这是国际化警告,具体如下:

 

Cause


A method or constructor created one or more System.Data.DataTable or System.Data.DataSet instances and did not explicitly set the locale property (System.Data.DataTable.Locale or System.Data.DataSet.Locale).

Rule Description

The locale determines culture-specific presentation elements for data, such as formatting used for numeric values, currency symbols, and sort order. When you create a DataTable or DataSet, you should set the locale explicitly. By default, the locale for these types is the current culture. For data that is stored in a database or file and is shared globally, the locale should ordinarily be set to the invariant culture (System.Globalization.CultureInfo.InvariantCulture). When data is shared across cultures, using the default locale can cause the contents of the DataTable or DataSet to be presented or interpreted incorrectly.

 

How to Fix Violations


To fix a violation of this rule, explicitly set the locale for the DataTable or DataSet.

 

 

此类警告最常见的未ToString() 格式化问题,暂时所有国际化警告:

Avoid duplicate accelerators

Do not hardcode locale specific strings

Do not pass literals as localized parameters

Set locale for data types

Specify CultureInfo

Specify IFormatProvider

Specify MessageBoxOptions

  

reference:

http://msdn.microsoft.com/en-us/library/ms182188(VS.80).aspx

http://msdn.microsoft.com/en-us/library/ms182184(v=VS.80).aspx

转载于:https://www.cnblogs.com/zzj8704/archive/2010/05/18/1738126.html

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!