TypeConverter.ConvertTo Método
Definição
Converte o objeto de valor atribuído no tipo especificado.Converts the given value object to the specified type.
Sobrecargas
| ConvertTo(Object, Type) |
Converte o objeto de valor especificado para o tipo especificado, usando os argumentos.Converts the given value object to the specified type, using the arguments. |
| ConvertTo(ITypeDescriptorContext, CultureInfo, Object, Type) |
Converte o objeto de valor determinado para o tipo especificado, usando o contexto especificado e as informações da cultura.Converts the given value object to the specified type, using the specified context and culture information. |
ConvertTo(Object, Type)
Converte o objeto de valor especificado para o tipo especificado, usando os argumentos.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);
member this.ConvertTo : obj * Type -> obj
Public Function ConvertTo (value As Object, destinationType As Type) As Object
Parâmetros
- destinationType
- Type
O Type para converter o parâmetro value.The Type to convert the value parameter to.
Retornos
Um Object que representa o valor convertido.An Object that represents the converted value.
Exceções
O parâmetro destinationType é null.The destinationType parameter is null.
A conversão não pode ser executada.The conversion cannot be performed.
Comentários
O tipo mais comum para converter em e de é um objeto de cadeia de caracteres.The most common type to convert to and from is a string object. Essa implementação chama ToString o objeto, se o objeto for válido e se o tipo de destino for uma cadeia de caracteres.This implementation calls ToString on the object, if the object is valid and if the destination type is a string.
Aplica-se a
ConvertTo(ITypeDescriptorContext, CultureInfo, Object, Type)
Converte o objeto de valor determinado para o tipo especificado, usando o contexto especificado e as informações da cultura.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);
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
Parâmetros
- context
- ITypeDescriptorContext
Um ITypeDescriptorContext que fornece um contexto de formato.An ITypeDescriptorContext that provides a format context.
- culture
- CultureInfo
Um CultureInfo.A CultureInfo. Se null for passado, a cultura atual será assumida.If null is passed, the current culture is assumed.
- destinationType
- Type
O Type para converter o parâmetro value.The Type to convert the value parameter to.
Retornos
Um Object que representa o valor convertido.An Object that represents the converted value.
Exceções
O parâmetro destinationType é null.The destinationType parameter is null.
A conversão não pode ser executada.The conversion cannot be performed.
Comentários
Os tipos mais comuns para converter são de e para um objeto de cadeia de caracteres.The most common types to convert are to and from a string object. Essa implementação chama ToString o objeto se o objeto for válido e se o tipo de destino for uma cadeia de caracteres.This implementation calls ToString on the object if the object is valid and if the destination type is a string.
Use o context parâmetro para extrair informações adicionais sobre o ambiente do qual esse conversor é invocado.Use the context parameter to extract additional information about the environment from which this converter is invoked. Esse parâmetro pode ser null , portanto, sempre verifique.This parameter can be null, so always check it. Além disso, as propriedades no objeto de contexto podem retornar null.Also, properties on the context object can return null.
Os autores de tipo personalizado que pretendem dar suporte a um comportamento de conversão de tipo para XAML normalmente implementam uma TypeConverter classe que dá suporte ao ConvertFrom comportamento de uma cadeia de caracteres.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. Esses conversores de tipo também podem implementar ConvertTo para dar suporte à serialização de volta para XAML.These type converters might also implement ConvertTo to support serialization back to XAML.
Alguns cenários de serialização XAML não podem ser adequadamente resolvidos com TypeConverter apenas.Some XAML serialization scenarios cannot be adequately addressed with TypeConverter alone. Nesses casos, pode ser necessário também definir um ValueSerializer que manipule os casos de serialização que, de outra forma, seriam manipulados ConvertTo .In these cases, it may be necessary to also define a ValueSerializer that handles the serialization cases that would otherwise be handled by ConvertTo. Para obter mais informações, consulte ValueSerializer.For more information, see ValueSerializer.
Notas aos Herdeiros
Substitua esse método para fornecer seus próprios requisitos de conversão.Override this method to provide your own conversion requirements.
Para obter padrões de implementação para conversores de tipo que são usados para dar suporte a XAML e tipos personalizados, consulte conversores de tipo para visão geral de XAML.For implementation patterns for type converters that are used to support XAML and custom types, see Type Converters for XAML Overview.
Confira também
- ITypeDescriptorContext
- Visão geral dos conversores de tipo para XAMLOverview of type converters for XAML