TypeConverter.ConvertFromString TypeConverter.ConvertFromString TypeConverter.ConvertFromString TypeConverter.ConvertFromString Method

定义

将指定文本转换为对象。Converts the specified text to an object.

重载

ConvertFromString(ITypeDescriptorContext, CultureInfo, String) ConvertFromString(ITypeDescriptorContext, CultureInfo, String) ConvertFromString(ITypeDescriptorContext, CultureInfo, String) ConvertFromString(ITypeDescriptorContext, CultureInfo, String)

使用指定的上下文和区域性信息将给定的文本转换为对象。Converts the given text to an object, using the specified context and culture information.

ConvertFromString(String) ConvertFromString(String) ConvertFromString(String) ConvertFromString(String)

将指定文本转换为对象。Converts the specified text to an object.

ConvertFromString(ITypeDescriptorContext, String) ConvertFromString(ITypeDescriptorContext, String) ConvertFromString(ITypeDescriptorContext, String) ConvertFromString(ITypeDescriptorContext, String)

使用指定的上下文将给定的文本转换为对象。Converts the given text to an object, using the specified context.

ConvertFromString(ITypeDescriptorContext, CultureInfo, String) ConvertFromString(ITypeDescriptorContext, CultureInfo, String) ConvertFromString(ITypeDescriptorContext, CultureInfo, String) ConvertFromString(ITypeDescriptorContext, CultureInfo, String)

使用指定的上下文和区域性信息将给定的文本转换为对象。Converts the given text to an object, using the specified context and culture information.

public:
 System::Object ^ ConvertFromString(System::ComponentModel::ITypeDescriptorContext ^ context, System::Globalization::CultureInfo ^ culture, System::String ^ text);
public object ConvertFromString (System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, string text);
member this.ConvertFromString : System.ComponentModel.ITypeDescriptorContext * System.Globalization.CultureInfo * string -> obj
Public Function ConvertFromString (context As ITypeDescriptorContext, culture As CultureInfo, text As String) As Object

参数

context
ITypeDescriptorContext ITypeDescriptorContext ITypeDescriptorContext ITypeDescriptorContext

一个 ITypeDescriptorContext,用于提供格式上下文。An ITypeDescriptorContext that provides a format context.

culture
CultureInfo CultureInfo CultureInfo CultureInfo

CultureInfoA CultureInfo. 如果传递 null,则采用当前区域性。If null is passed, the current culture is assumed.

text
String String String String

要转换的 StringThe String to convert.

返回

一个 Object,表示已转换的文本。An Object that represents the converted text.

异常

无法执行转换。The conversion cannot be performed.

注解

如果字符串无法转换为相应的对象, 则会引发异常。An exception is raised if the string cannot be converted into the appropriate object. 默认实现始终返回 nullThe default implementation always returns null.

使用 context 参数提取有关调用此转换器的环境的附加信息。Use the context parameter to extract additional information about the environment from which this converter is invoked. 此参数可以是null, 因此请始终选中此参数。This parameter can be null, so always check it. 同样,上下文对象的属性可以返回 nullAlso, properties on the context object can return null.

另请参阅

ConvertFromString(String) ConvertFromString(String) ConvertFromString(String) ConvertFromString(String)

将指定文本转换为对象。Converts the specified text to an object.

public:
 System::Object ^ ConvertFromString(System::String ^ text);
public object ConvertFromString (string text);
member this.ConvertFromString : string -> obj
Public Function ConvertFromString (text As String) As Object

参数

text
String String String String

要转换的对象的文本表示形式。The text representation of the object to convert.

返回

一个 Object,表示已转换的文本。An Object that represents the converted text.

异常

该字符串不能转换为适当的对象。The string cannot be converted into the appropriate object.

示例

有关此函数的示例, 请参见TypeConverter类。For an example of this function, see the TypeConverter class.

注解

默认实现始终返回 nullThe default implementation always returns null.

ConvertFromString(ITypeDescriptorContext, String) ConvertFromString(ITypeDescriptorContext, String) ConvertFromString(ITypeDescriptorContext, String) ConvertFromString(ITypeDescriptorContext, String)

使用指定的上下文将给定的文本转换为对象。Converts the given text to an object, using the specified context.

public:
 System::Object ^ ConvertFromString(System::ComponentModel::ITypeDescriptorContext ^ context, System::String ^ text);
public object ConvertFromString (System.ComponentModel.ITypeDescriptorContext context, string text);
member this.ConvertFromString : System.ComponentModel.ITypeDescriptorContext * string -> obj
Public Function ConvertFromString (context As ITypeDescriptorContext, text As String) As Object

参数

context
ITypeDescriptorContext ITypeDescriptorContext ITypeDescriptorContext ITypeDescriptorContext

一个 ITypeDescriptorContext,用于提供格式上下文。An ITypeDescriptorContext that provides a format context.

text
String String String String

要转换的 StringThe String to convert.

返回

一个 Object,表示已转换的文本。An Object that represents the converted text.

异常

无法执行转换。The conversion cannot be performed.

注解

如果字符串无法转换为相应的对象, 则会引发异常。An exception is raised if the string cannot be converted into the appropriate object. 默认实现始终返回 nullThe default implementation always returns null.

使用 context 参数提取有关调用此转换器的环境的附加信息。Use the context parameter to extract additional information about the environment from which this converter is invoked. 此参数可以是null, 因此请始终选中此参数。This parameter can be null, so always check it. 同样,上下文对象的属性可以返回 nullAlso, properties on the context object can return null.

另请参阅

适用于