TypeConverter.ConvertFrom Method (ITypeDescriptorContext, CultureInfo, Object)

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Converts from the specified value to the intended conversion type of the converter.

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

Syntax

'Declaration
Public Overridable Function ConvertFrom ( _
    context As ITypeDescriptorContext, _
    culture As CultureInfo, _
    value As Object _
) As Object
public virtual Object ConvertFrom(
    ITypeDescriptorContext context,
    CultureInfo culture,
    Object value
)

Parameters

  • value
    Type: System.Object
    The value to convert to the type of this converter.

Return Value

Type: System.Object
The converted value.

Exceptions

Exception Condition
NotImplementedException

ConvertFrom not implemented in base TypeConverter.

Remarks

NotImplementedException is thrown by the base implementation and will be surfaced either if an implementation call falls to the base implementation (there was no relevant override) or if you call base deliberately.

Notes to Inheritors

For use as a type converter for custom-type attribute handling in Silverlight XAML, you should define the ConvertFrom signature with your implementation.

  • Do not rely on information in context, it may be null.

  • Do not throw if context is nullor if culture is null; ConvertFromString calls this signature, passing nulla null reference (Nothing in Visual Basic) for both culture and context.

  • culture when called by the XAML parser is always the en-us culture, so you can assume that behavior if you are writing a TypeConverter that supports XAML parsing. Writing behavior for other culture values might be useful if you intend to support type conversion for scenarios other than XAML support.

  • Always return one of the following: a valid object that is the target conversion type of your converter, or null.

  • Raising exceptions is permissible (unhandled exceptions you throw from a type converter will generate a XamlParseException when the converter is invoked by the XAML parser, possibly with your exception as inner exception).

  • A common practice for a ConvertFrom implementation is to call a relevant class constructor, based on processing any relevant string information found in value into a specific constructor signature.

  • Alternatively, you could call the default constructor, then set properties on the created instance before returning it. The call to the constructor is a good way to ensure that the conversion behavior for XAML is well-aligned with the behavior that is used to create an equivalent object in code, and raises the same exceptions if input is invalid.

Version Information

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

Platforms

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