Informations
Le sujet que vous avez demandé est indiqué ci-dessous. Toutefois, ce sujet ne figure pas dans la bibliothèque.

TypeConverter Class

Provides a unified way of converting types of values to other types. TypeConverter typically supports string-to-object conversion, either for property editors in design environments, or to enable XAML usages.

Namespace:  System.ComponentModel
Assembly:  System (in System.dll)

public class TypeConverter

The TypeConverter type exposes the following members.

  NameDescription
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360TypeConverterInitializes a new instance of the TypeConverter class.
Top

  NameDescription
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360CanConvertFrom(Type)Returns whether the type converter can convert an object from the specified type to the type of this converter.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360CanConvertFrom(ITypeDescriptorContext, Type)Returns whether the type converter can convert an object from the specified type to the type of this converter.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360CanConvertTo(Type)Returns whether the type converter can convert an object to the specified type.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360CanConvertTo(ITypeDescriptorContext, Type)Returns whether the type converter can convert an object to the specified type.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360ConvertFrom(Object)Converts from the specified value to the type of this converter.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360ConvertFrom(ITypeDescriptorContext, CultureInfo, Object)Converts from the specified value to the intended conversion type of the converter.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360ConvertFromStringConverts the specified text to an object.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360ConvertTo(Object, Type)Converts the specified value object to the specified type.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360ConvertTo(ITypeDescriptorContext, CultureInfo, Object, Type)Converts the specified value object to the specified type.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360ConvertToStringConverts the specified object to a string representation.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360Equals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodSupported by Silverlight for Windows PhoneSupported by Xbox 360FinalizeAllows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360GetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360GetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodSupported by Silverlight for Windows PhoneSupported by Xbox 360MemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360ToStringReturns a string that represents the current object. (Inherited from Object.)
Top

The most common type of converter is one that converts to and from a text or string representation. The type converter for a class is associated with the class by applying a TypeConverterAttribute in the class definition. Unless this attribute is overridden, all classes that inherit from this class use the same type converter as the base class.

The most common scenario for TypeConverter in Silverlight is to support setting XAML attribute values and generating object values when XAML is parsed, both for Silverlight defined classes and custom classes. See TypeConverters and XAML.

Notes to Implementers

To support the string creation syntax of custom types that are specified as attributes in XAML, you should implement CanConvertFrom(ITypeDescriptorContext, Type) and ConvertFrom(ITypeDescriptorContext, CultureInfo, Object) in your TypeConverter class.

For Silverlight 4, implementing CanConvertTo and ConvertTo is not crucial, because Silverlight 4 XAML does not support a general serialization mechanism. However, you might still consider providing a basic CanConvertTo and ConvertTo implementation that reverses the ConvertFrom(ITypeDescriptorContext, CultureInfo, Object) in your TypeConverter  conversion. This will produce a more robust and generalized TypeConverter for anyone that specifically calls the ConvertTo method.

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Ajouts de la communauté

Afficher:
© 2014 Microsoft