Fxcop:Globlization warning/全球化警告

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

  • posted @ 2010-05-18 13:02  Zhongjian Zhang  阅读(1419)  评论(0编辑  收藏  举报