Search Results for

    Show / Hide Table of Contents

    Class UnionJsonConverter<T>

    Abstract base class for JSON converters that handle polymorphic types based on a type discriminator field.

    Inheritance
    object
    JsonConverter
    JsonConverter<T>
    UnionJsonConverter<T>
    Inherited Members
    JsonConverter<T>.WriteJson(JsonWriter, object, JsonSerializer)
    JsonConverter<T>.ReadJson(JsonReader, Type, object, JsonSerializer)
    JsonConverter<T>.CanConvert(Type)
    JsonConverter.CanRead
    JsonConverter.CanWrite
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: Glitch9.IO.Json
    Assembly: Glitch9.IO.dll
    Syntax
    public abstract class UnionJsonConverter<T> : JsonConverter<T>
    Type Parameters
    Name Description
    T

    The base type to convert.

    Properties

    | Edit this page View Source

    DiscriminatorFieldName

    Declaration
    protected virtual string DiscriminatorFieldName { get; }
    Property Value
    Type Description
    string

    Methods

    | Edit this page View Source

    CreateInstance(string)

    Creates an instance of the appropriate derived type based on the type discriminator value.

    Declaration
    protected abstract T CreateInstance(string type)
    Parameters
    Type Name Description
    string type

    The type discriminator value from the JSON.

    Returns
    Type Description
    T

    An instance of the derived type, or null if the type is not recognized.

    | Edit this page View Source

    GetDiscriminatorValue(JObject)

    Gets the name of the JSON field used as the type discriminator.

    Declaration
    protected virtual string GetDiscriminatorValue(JObject jo)
    Parameters
    Type Name Description
    JObject jo
    Returns
    Type Description
    string

    The field name (default: "type").

    | Edit this page View Source

    ReadJson(JsonReader, Type, T, bool, JsonSerializer)

    Reads the JSON representation of the object.

    Declaration
    public override T ReadJson(JsonReader reader, Type objectType, T existingValue, bool hasExistingValue, JsonSerializer serializer)
    Parameters
    Type Name Description
    JsonReader reader

    The Newtonsoft.Json.JsonReader to read from.

    Type objectType

    Type of the object.

    T existingValue

    The existing value of object being read. If there is no existing value then null will be used.

    bool hasExistingValue

    The existing value has a value.

    JsonSerializer serializer

    The calling serializer.

    Returns
    Type Description
    T

    The object value.

    Overrides
    JsonConverter<T>.ReadJson(JsonReader, Type, T, bool, JsonSerializer)
    | Edit this page View Source

    ResolveDiscriminatorValue(T)

    Declaration
    protected virtual string ResolveDiscriminatorValue(T value)
    Parameters
    Type Name Description
    T value
    Returns
    Type Description
    string
    | Edit this page View Source

    WriteJson(JsonWriter, T, JsonSerializer)

    Writes the JSON representation of the object.

    Declaration
    public override void WriteJson(JsonWriter writer, T value, JsonSerializer serializer)
    Parameters
    Type Name Description
    JsonWriter writer

    The Newtonsoft.Json.JsonWriter to write to.

    T value

    The value.

    JsonSerializer serializer

    The calling serializer.

    Overrides
    Newtonsoft.Json.JsonConverter<T>.WriteJson(Newtonsoft.Json.JsonWriter, T, Newtonsoft.Json.JsonSerializer)

    Extension Methods

    ArrayExtensions.ToArrayOrEmpty<T>(T)
    ArrayExtensions.ToArrayOrNull<T>(T)
    EventExtensions.ToDelta<T>(T, string, int, string, bool)
    EventExtensions.ToDone<T>(T, string, int, string)
    EventExtensions.ToEvent<T>(T)
    EventExtensions.UpcastDelta<T1, T2>(T1, string, int, string, bool)
    FallbackExtensions.IsOr<TParent, TChild>(TParent, TChild)
    ResponseCastingExtensions.GetResult<T>(T)
    SystemExtensions.GetName(object)
    • Edit this page
    • View Source
    In this article
    Back to top AI DevKit Documentation