Assembly: OptimaJet.Workflow.Core

Class NewtonsoftStringTypeConverter

OptimaJet.Workflow.Core.Designer.NewtonsoftStringTypeConverter

Provides a JsonConverter that serializes and deserializes Type values as URL-encoded friendly type names.

public class NewtonsoftStringTypeConverter : JsonConverter

Type Hierarchy

  • JsonConverter
    • NewtonsoftStringTypeConverter Current type

Methods

public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) #
Writes a Type as a URL-encoded friendly type name.

Parameters

Name
Type
Description
writer
JsonWriter
The JsonWriter that receives the JSON value.
value
Object
The value to serialize. A Type is written as a JSON string; any other value is written as JSON null.
serializer
JsonSerializer
The JsonSerializer for the serialization operation.

Example

Serializing typeof(System.Collections.Generic.Dictionary<string, int>) writes the JSON string "System.Collections.Generic.Dictionary%3CString%2CInt32%3E".
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) #
Reads a URL-encoded friendly type name and resolves it to a Type.

Parameters

Name
Type
Description
reader
JsonReader
The JsonReader that provides the JSON value.
objectType
Type
The type of the object being deserialized.
existingValue
Object
The existing value of the object being deserialized.
serializer
JsonSerializer
The JsonSerializer for the deserialization operation.

Returns

Type
Description
Object
The resolved Type, or null when the JSON value is null.

Exceptions

Type
Description
TypeParsingException
The JSON value cannot be decoded or resolved to a Type.

Example

Reading the JSON string "System.Collections.Generic.Dictionary%3CString%2CInt32%3E" returns typeof(System.Collections.Generic.Dictionary<string, int>).
public override bool CanConvert(Type objectType) #
Determines whether objectType is exactly Type.

Parameters

Name
Type
Description
objectType
Type
The type to check.

Returns

Type
Description
Boolean
true if objectType is Type; otherwise, false.

Example

CanConvert(typeof(Type)) returns true, while CanConvert(typeof(string)) returns false.