Table of Contents

Class JsonSerializerExt

Namespace
VpnHood.Net.Toolkit.Utils
Assembly
VpnHood.Net.Toolkit.dll

Provides the means to merge JSON into an existing object, by reflection.

[SuppressMessage("ReSharper", "UnusedMember.Global")]
public static class JsonSerializerExt
Inheritance
JsonSerializerExt
Inherited Members

Methods

PopulateObject(object, string, Type)

Sets an object's properties from the JSON's, as PopulateObject<T>(T, string) does.

public static void PopulateObject(object target, string jsonSource, Type type)

Parameters

target object

The object.

jsonSource string

The JSON object.

type Type

The type whose properties are set.

Exceptions

JsonException

The text is not JSON, or a value does not fit its property.

InvalidOperationException

A JSON value is not of the kind the property needs.

UriFormatException

A Uri property's text is not a URI.

PopulateObject<T>(T, string)

Sets an object's properties from the JSON's, by exact name: a value-type, string or Uri property, a JSON array or a null replaces the value; another JSON object merges into the property's current object, and a null property stays null. A name the type does not have is passed over.

public static void PopulateObject<T>(T target, string jsonSource) where T : class

Parameters

target T

The object.

jsonSource string

The JSON object.

Type Parameters

T

The object's type, whose properties are set.

Exceptions

JsonException

The text is not JSON, or a value does not fit its property.

InvalidOperationException

A JSON value is not of the kind the property needs.

UriFormatException

A Uri property's text is not a URI.