Поделиться через


ScriptObject.ConvertTo<T> Method

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

Converts the current scriptable object to a specified type.

Namespace:  System.Windows.Browser
Assembly:  System.Windows.Browser (in System.Windows.Browser.dll)

Syntax

'Declaration
Public Function ConvertTo(Of T) As T
public T ConvertTo<T>()

Type Parameters

  • T
    The type to convert the current scriptable object to.

Return Value

Type: T
An object of type T.

Exceptions

Exception Condition
ArgumentException

The conversion failed or is not supported.

Remarks

This method converts the scriptable object to the type specified by T.

NoteNote:

Use this method to convert a JavaScript Date object into a managed DateTime object.

Conversion operations differ depending on the underlying type of the scriptable object:

  • If the ManagedObject property is not nulla null reference (Nothing in Visual Basic), an attempt is made to cast the underlying managed object to type T. As a result, ConvertTo is an alternative to explicitly casting the ManagedObject property.

  • If the current scriptable object is an event delegate, you can call ConvertTo<EventHandler> to get a ScriptEventHandler that represents the scriptable object. For example, this is possible if the underlying scriptable object is actually a JavaScript method.

  • For all other types (except HtmlObject) an attempt is made to serialize the underlying JavaScript object to the JavaScript Object Notation (JSON), and then to deserialize the resulting JSON string to the target T type.

Version Information

Silverlight

Supported in: 5, 4, 3

Platforms

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