Muokkaa

Jaa


JavaScriptConverter.Deserialize Method

Definition

When overridden in a derived class, converts the provided dictionary into an object of the specified type.

public:
 abstract System::Object ^ Deserialize(System::Collections::Generic::IDictionary<System::String ^, System::Object ^> ^ dictionary, Type ^ type, System::Web::Script::Serialization::JavaScriptSerializer ^ serializer);
public abstract object Deserialize (System.Collections.Generic.IDictionary<string,object> dictionary, Type type, System.Web.Script.Serialization.JavaScriptSerializer serializer);
abstract member Deserialize : System.Collections.Generic.IDictionary<string, obj> * Type * System.Web.Script.Serialization.JavaScriptSerializer -> obj
Public MustOverride Function Deserialize (dictionary As IDictionary(Of String, Object), type As Type, serializer As JavaScriptSerializer) As Object

Parameters

dictionary
IDictionary<String,Object>

An IDictionary<TKey,TValue> instance of property data stored as name/value pairs.

type
Type

The type of the resulting object.

serializer
JavaScriptSerializer

The JavaScriptSerializer instance.

Returns

The deserialized object.

Notes to Implementers

The Deserialize(IDictionary<String,Object>, Type, JavaScriptSerializer) method iterates through the values in the dictionary parameter to construct an instance of the type requested in the type parameter. Although a converter can directly use values from dictionary, we recommend that the converter implementer use the ConvertToType<T>(Object) method instead. The converter should call this method of the JavaScriptSerializer instance available from the serializer parameter.

The ConvertToType<T>(Object) method enables converter to pass a property value from dictionary, and then return a value of the expected type. In some cases, a converter for a custom type might be working with properties that themselves have registered converters (for example, type A has a property of type B, and type B is also associated with a custom converter). In that case, invoking ConvertToType<T>(Object) makes sure that custom converters will be recursively invoked for property data that is contained in the dictionary. When the converter has iterated through all entries in the dictionary, it returns a constructed instance of the target type.

If the converter encounters a problem during deserialization, it should throw an InvalidOperationException error that describes the problem.

Applies to