Breyta

Deila með


TypeConverter.ConvertTo Method

Definition

Converts the given value object to the specified type.

Overloads

ConvertTo(Object, Type)

Converts the given value object to the specified type, using the arguments.

ConvertTo(ITypeDescriptorContext, CultureInfo, Object, Type)

Converts the given value object to the specified type, using the specified context and culture information.

ConvertTo(Object, Type)

Source:
TypeConverter.cs
Source:
TypeConverter.cs
Source:
TypeConverter.cs

Converts the given value object to the specified type, using the arguments.

public:
 System::Object ^ ConvertTo(System::Object ^ value, Type ^ destinationType);
public object ConvertTo (object value, Type destinationType);
public object? ConvertTo (object? value, Type destinationType);
member this.ConvertTo : obj * Type -> obj
Public Function ConvertTo (value As Object, destinationType As Type) As Object

Parameters

value
Object

The Object to convert.

destinationType
Type

The Type to convert the value parameter to.

Returns

An Object that represents the converted value.

Exceptions

The destinationType parameter is null.

The conversion cannot be performed.

Remarks

The most common type to convert to and from is a string object. This implementation calls ToString on the object, if the object is valid and if the destination type is a string.

Applies to

ConvertTo(ITypeDescriptorContext, CultureInfo, Object, Type)

Source:
TypeConverter.cs
Source:
TypeConverter.cs
Source:
TypeConverter.cs

Converts the given value object to the specified type, using the specified context and culture information.

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

Parameters

context
ITypeDescriptorContext

An ITypeDescriptorContext that provides a format context.

culture
CultureInfo

A CultureInfo. If null is passed, the current culture is assumed.

value
Object

The Object to convert.

destinationType
Type

The Type to convert the value parameter to.

Returns

An Object that represents the converted value.

Exceptions

The destinationType parameter is null.

The conversion cannot be performed.

Remarks

The most common types to convert are to and from a string object. This implementation calls ToString on the object if the object is valid and if the destination type is a string.

Use the context parameter to extract additional information about the environment from which this converter is invoked. This parameter can be null, so always check it. Also, properties on the context object can return null.

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. These type converters might also implement ConvertTo to support serialization back to XAML.

Some XAML serialization scenarios cannot be adequately addressed with TypeConverter alone. In these cases, it may be necessary to also define a ValueSerializer that handles the serialization cases that would otherwise be handled by ConvertTo. For more information, see ValueSerializer.

Notes to Inheritors

Override this method to provide your own conversion requirements.

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