TypeConverter.ConvertFrom 方法

定義

會將指定值轉換為這個轉換子的型別。Converts the given value to the type of this converter.

多載

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

參數

value
Object

要進行轉換的 ObjectThe Object to convert.

傳回

Object,代表轉換過的值。An Object that represents the converted value.

例外狀況

無法執行轉換作業。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

參數

context
ITypeDescriptorContext

提供格式內容的 ITypeDescriptorContextAn ITypeDescriptorContext that provides a format context.

culture
CultureInfo

要用作目前文化特性的 CultureInfoThe CultureInfo to use as the current culture.

value
Object

要進行轉換的 ObjectThe Object to convert.

傳回

Object,代表轉換過的值。An Object that represents the converted value.

例外狀況

無法執行轉換作業。The conversion cannot be performed.

備註

想要支援 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.

給繼承者的注意事項

請覆寫這個方法以提供您自己的轉換需求。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.

另請參閱

適用於