Documentation for: ASP.NET Ajax Version 1.0

This documentation is for a previous version. For the current released version, see the ASP.NET Ajax documentation on MSDN.

 

 

 

 

 

 

 

RegisterConverters Method (converters)

Registers a custom converter with the JavaScriptSerializer instance.

Syntax

CSharp

public void RegisterConverters (
	IEnumerable<JavaScriptConverter> converters
)

VisualBasic

Public Sub RegisterConverters ( _
	converters As IEnumerable(Of JavaScriptConverter) _
)

ManagedCPlusPlus

public:
void RegisterConverters (
	IEnumerable<JavaScriptConverter^>^ converters
)

JSharp

public void RegisterConverters (
	IEnumerable<JavaScriptConverter> converters
)

Parameters

converters (IEnumerable<(Of JavaScriptConverter>))

An array of type JavaScriptConverter that contains the custom converters to be registered.

Remarks

You can register one or more custom converters with a JavaScriptSerializer instance by using the RegisterConverters(IEnumerable<(Of JavaScriptConverter>)) method. When custom converters are registered, JavaScriptSerializer uses the converters as part of both the serialization of managed types and the deserialization of JavaScript Object Notation (JSON) strings back to managed types.

Multiple converters can be registered against the same JavaScriptSerializer instance, and these converters might indicate support for the same type. As a result, the last converter that is registered for a specific type is the one that will be used by JavaScriptSerializer to serialize the type.

For more information about custom converters, see the JavaScriptConverter class.

Examples

The following example demonstrates how to register a custom converter with a JavaScriptSerializer instance. This code example is part of a larger example provided for the JavaScriptSerializer class.

CS

serializer = new JavaScriptSerializer();

// Register the custom converter.
serializer.RegisterConverters(new JavaScriptConverter[] { 
    new System.Web.Script.Serialization.CS.ListItemCollectionConverter() });

VB

serializer = New JavaScriptSerializer()

' Register the custom converter.
serializer.RegisterConverters(New JavaScriptConverter() _
    {New System.Web.Script.Serialization.VB.ListItemCollectionConverter()})

Exceptions

ExceptionCondition
ArgumentNullException

converters is null.

Assembly: System.Web.Extensions (Module: System.Web.Extensions)