CultureInfoConverter 类

提供将 CultureInfo 对象与其他各种表示形式相互转换的类型转换器。

**命名空间:**System.ComponentModel
**程序集:**System(在 system.dll 中)

语法

声明
Public Class CultureInfoConverter
    Inherits TypeConverter
用法
Dim instance As CultureInfoConverter
public class CultureInfoConverter : TypeConverter
public ref class CultureInfoConverter : public TypeConverter
public class CultureInfoConverter extends TypeConverter
public class CultureInfoConverter extends TypeConverter

备注

此转换器只能将 CultureInfo 对象与字符串相互转换。

有关类型转换器的更多信息,请参见 TypeConverter 基类和 如何:实现类型转换器

提示

决不要创建 CultureInfoConverter 类的实例。而应调用 TypeDescriptor 类的 GetConverter 方法。有关更多信息,请参见 TypeConverter 基类中的示例。

应用于此类的 HostProtectionAttribute 属性 (Attribute) 具有以下 Resources 属性 (Property) 值:SharedStateHostProtectionAttribute 不影响桌面应用程序(桌面应用程序一般通过双击图标,键入命令或在浏览器中输入 URL 启动)。有关更多信息,请参见 HostProtectionAttribute 类或 SQL Server 编程和宿主保护属性

示例

下面的代码示例可将 CultureInfo 类型的变量转换为字符串,并可将字符串转换为该类型的变量。首先,它使用 Greek 区域性(由“el”表示)构造 CultureInfo 变量并将其转换为字符串“Greek”。然后,它将字符串“Russian”转换为 CultureInfo 表示形式“ru”。

' The sample first constructs a CultureInfo variable using the Greek culture - 'el'.
Dim myCulture As New System.Globalization.CultureInfo("el")
Dim myCString As String = "Russian"
Console.WriteLine(TypeDescriptor.GetConverter(myCulture).ConvertTo(myCulture, GetType(String)))
' The following line will output 'ru' based on the string being converted.
Console.WriteLine(TypeDescriptor.GetConverter(myCulture).ConvertFrom(myCString))
// The sample first constructs a CultureInfo variable using the Greek culture - 'el'.
System.Globalization.CultureInfo myCulture= new System.Globalization.CultureInfo("el");
string myCString="Russian";
Console.WriteLine(TypeDescriptor.GetConverter(myCulture).ConvertTo(myCulture, typeof(string)));
// The following line will output 'ru' based on the string being converted.
Console.WriteLine(TypeDescriptor.GetConverter(myCulture).ConvertFrom(myCString));
// The sample first constructs a CultureInfo variable using the Greek culture - 'el'.
System::Globalization::CultureInfo^ myCulture = gcnew System::Globalization::CultureInfo( "el" );
String^ myCString = "Russian";
Console::WriteLine( TypeDescriptor::GetConverter( myCulture )->ConvertTo( myCulture, String::typeid ) );
// The following line will output 'ru' based on the string being converted.
Console::WriteLine( TypeDescriptor::GetConverter( myCulture )->ConvertFrom( myCString ) );
// The sample first constructs a CultureInfo variable using the 
// Greek culture - 'el'.
System.Globalization.CultureInfo myCulture = new System.Globalization.
    CultureInfo("el");
String myCString = "Russian";
Console.WriteLine(TypeDescriptor.GetConverter(myCulture).
    ConvertTo(myCulture, String.class.ToType()));
// The following line will output 'ru' based on the 
// string being converted.
Console.WriteLine(TypeDescriptor.GetConverter(myCulture).
    ConvertFrom(myCString));

继承层次结构

System.Object
   System.ComponentModel.TypeConverter
    System.ComponentModel.CultureInfoConverter

线程安全

此类型的任何公共静态(Visual Basic 中的 Shared)成员都是线程安全的,但不保证所有实例成员都是线程安全的。

平台

Windows 98、Windows 2000 SP4、Windows Millennium Edition、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

请参见

参考

CultureInfoConverter 成员
System.ComponentModel 命名空间