TypeConverter.ConvertFrom Method

Definition

将给定值转换为此转换器的类型。Converts the given value to the type of this converter.

Overloads

ConvertFrom(Object)

将给定值转换为此转换器的类型。Converts the given value to the type of this converter.

ConvertFrom(ITypeDescriptorContext, CultureInfo, Object)

使用指定的上下文和区域性信息将给定对象转换为此转换器的类型。Converts the given object to the type of this converter, using the specified context and culture information.

ConvertFrom(Object)

将给定值转换为此转换器的类型。Converts the given value to the type of this converter.

public:
 System::Object ^ ConvertFrom(System::Object ^ value);
public object ConvertFrom (object value);
member this.ConvertFrom : obj -> obj
Public Function ConvertFrom (value As Object) As Object

Parameters

value
Object

要转换的 ObjectThe Object to convert.

Returns

Object

表示转换的值的 ObjectAn Object that represents the converted value.

Exceptions

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

ConvertFrom(ITypeDescriptorContext, CultureInfo, Object)

使用指定的上下文和区域性信息将给定对象转换为此转换器的类型。Converts the given object to the type of this converter, using the specified context and culture information.

public:
 virtual System::Object ^ ConvertFrom(System::ComponentModel::ITypeDescriptorContext ^ context, System::Globalization::CultureInfo ^ culture, System::Object ^ value);
public virtual object ConvertFrom (System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value);
abstract member ConvertFrom : System.ComponentModel.ITypeDescriptorContext * System.Globalization.CultureInfo * obj -> obj
override this.ConvertFrom : System.ComponentModel.ITypeDescriptorContext * System.Globalization.CultureInfo * obj -> obj
Public Overridable Function ConvertFrom (context As ITypeDescriptorContext, culture As CultureInfo, value As Object) As Object

Parameters

context
ITypeDescriptorContext

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

culture
CultureInfo

要用作当前区域性的 CultureInfo 对象。The CultureInfo to use as the current culture.

value
Object

要转换的 ObjectThe Object to convert.

Returns

Object

表示转换的值的 ObjectAn Object that represents the converted value.

Exceptions

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

Remarks

要支持 XAML 的类型转换行为的自定义类型创作者通常实现 TypeConverter 类,该类支持字符串 ConvertFrom 行为。Custom type authors that intend to support a type conversion behavior for XAML typically implement a TypeConverter class that supports ConvertFrom behavior from a string. 此行为可实现从提供的字符串到 XAML 特性值的类型转换,并为 XAML 处理器提供从字符串创建对象所需的支持,以便可以在分析的对象图中生成该对象。This behavior enables type conversion from the string provided as a XAML attribute value and provides a XAML processor with the support needed to create an object from the string, so that the object can be produced in a parsed object graph. 自定义类型或自定义类型的成员通过将 TypeConverterAttribute 应用于定义来指示,特性引用自定义 TypeConverter 实现。Custom types or members of custom types are indicated by applying TypeConverterAttribute to the definitions, with the attribute referencing the custom TypeConverter implementation.

出于 XAML 目的,您通常不会基于 culture提供分支实现。For XAML purposes, you do not typically provide branching implementations based on culture. 这是因为 XAML 是在开发环境上下文中预编译的,并且运行时 XAML 的区域性特定信息与 XAML 类型转换无关。This is because XAML is precompiled in a development environment context, and culture-specific information for runtime XAML is not relevant for XAML type conversion. 有关详细信息,请参阅XAML 的类型转换器概述For more information, see Type Converters for XAML Overview.

Notes to Inheritors

重写该方法以提供您自己的转换要求。Override this method to provide your own conversion requirements.

使用 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.

有关用于支持 XAML 和自定义类型的类型转换器的实现模式,请参阅XAML 的类型转换器概述For implementation patterns for type converters that are used to support XAML and custom types, see Type Converters for XAML Overview.

See also

Applies to