Table of Contents

Class JsonModelDictionary

Namespace
DuetAPI.ObjectModel
Assembly
DuetAPI.dll

Class for holding string keys and custom values

[JsonConverter(typeof(JsonModelDictionaryConverter))]
public sealed class JsonModelDictionary : IDictionary<string, JsonElement?>, ICollection<KeyValuePair<string, JsonElement?>>, IEnumerable<KeyValuePair<string, JsonElement?>>, IModelDictionary, IStaticModelObject, IModelObject, ICloneable, INotifyPropertyChanged, IDictionary, ICollection, IEnumerable, INotifyPropertyChanging
Inheritance
JsonModelDictionary
Implements
Inherited Members

Remarks

Key names are NOT converted to camel-case (unlike regular class properties)

Constructors

JsonModelDictionary(bool)

Class for holding string keys and custom values

public JsonModelDictionary(bool nullRemovesItems)

Parameters

nullRemovesItems bool

Defines if setting items to null effectively removes them

Remarks

Key names are NOT converted to camel-case (unlike regular class properties)

Properties

Count

Returns the number of items in this collection

public int Count { get; }

Property Value

int

IsFixedSize

Whether this dictionary has a fixed size

public bool IsFixedSize { get; }

Property Value

bool

IsReadOnly

Whether the dictionary is read-only

public bool IsReadOnly { get; }

Property Value

bool

IsSynchronized

If this is thread-safe

public bool IsSynchronized { get; }

Property Value

bool

this[object]

Basic index operator

public object this[object key] { get; set; }

Parameters

key object

Key object

Property Value

object

Value if found

this[string]

Index operator

public JsonElement? this[string key] { get; set; }

Parameters

key string

Key

Property Value

JsonElement?

Value

Keys

List of keys

public ICollection<string> Keys { get; }

Property Value

ICollection<string>

NullRemovesItems

Flags if keys can be removed again by setting their value to null

[JsonIgnore]
public bool NullRemovesItems { get; }

Property Value

bool

SyncRoot

Synchronization root

public object SyncRoot { get; }

Property Value

object

Values

List of values

public ICollection<JsonElement?> Values { get; }

Property Value

ICollection<JsonElement?>

Methods

Add(KeyValuePair<string, JsonElement?>)

Add a new item

public void Add(KeyValuePair<string, JsonElement?> item)

Parameters

item KeyValuePair<string, JsonElement?>

Item to add

Add(object, object?)

Add a new item

public void Add(object key, object? value)

Parameters

key object

Key to add

value object

Value to add

Add(string, JsonElement?)

Add a new item

public void Add(string key, JsonElement? value)

Parameters

key string

Key to add

value JsonElement?

Value to add

Assign(IStaticModelObject)

Assign the properties from another instance

public void Assign(IStaticModelObject from)

Parameters

from IStaticModelObject

Other instance

Clear()

Clear this dictionary

public void Clear()

Clone()

Create a clone of this instance

public object Clone()

Returns

object

Contains(KeyValuePair<string, JsonElement?>)

Check if a key-value pair exists

public bool Contains(KeyValuePair<string, JsonElement?> item)

Parameters

item KeyValuePair<string, JsonElement?>

Item to check

Returns

bool

If the item exists in the dictionary

Contains(object)

Check if a key is present

public bool Contains(object key)

Parameters

key object

Key to check

Returns

bool

Whether the key is present

ContainsKey(string)

Check if a key is present

public bool ContainsKey(string key)

Parameters

key string

Key to check

Returns

bool

Whether the key is present

CopyTo(Array, int)

Copy this instance to another array

public void CopyTo(Array array, int index)

Parameters

array Array

Destination array

index int

Start index

CopyTo(KeyValuePair<string, JsonElement?>[], int)

Copy this instance to another dictionary

public void CopyTo(KeyValuePair<string, JsonElement?>[] array, int arrayIndex)

Parameters

array KeyValuePair<string, JsonElement?>[]

Destination array

arrayIndex int

Start iondex

GetEnumerator()

Get an enumerator for this instance

public IEnumerator<KeyValuePair<string, JsonElement?>> GetEnumerator()

Returns

IEnumerator<KeyValuePair<string, JsonElement?>>

Enumerator instance

Remove(KeyValuePair<string, JsonElement?>)

Remove a key-value pair if applicable

public bool Remove(KeyValuePair<string, JsonElement?> item)

Parameters

item KeyValuePair<string, JsonElement?>

Item to remove

Returns

bool

If the key-value pair was present

Remove(object)

Remove a key (only supported if NullRemovesItems is true)

public void Remove(object key)

Parameters

key object

Key to remove

Remove(string)

Remove a key (only supported if NullRemovesItems is true)

public bool Remove(string key)

Parameters

key string

Key to remove

Returns

bool

Whether the key could be found

TryGetValue(string, out JsonElement?)

Try to get a value

public bool TryGetValue(string key, out JsonElement? value)

Parameters

key string

Key to look up

value JsonElement?

Retrieved value

Returns

bool

Whether the key could be found

UpdateFromJson(JsonElement, bool)

Update this instance from a given JSON element

public void UpdateFromJson(JsonElement jsonElement, bool ignoreSbcProperties)

Parameters

jsonElement JsonElement

Element to update this intance from

ignoreSbcProperties bool

Whether SBC properties are ignored

Remarks

Accepts null as the JSON value to clear existing items

Exceptions

JsonException

Failed to deserialize data

UpdateFromJsonReader(ref Utf8JsonReader, bool)

Update this instance from a given JSON reader

public void UpdateFromJsonReader(ref Utf8JsonReader reader, bool ignoreSbcProperties)

Parameters

reader Utf8JsonReader

JSON reader

ignoreSbcProperties bool

Whether SBC properties are ignored

Exceptions

JsonException

Failed to deserialize data

Events

DictionaryCleared

Event that is called when the entire directory is cleared. Only used if NullRemovesItems is false

public event EventHandler? DictionaryCleared

Event Type

EventHandler

PropertyChanged

Event that is called when a key has been changed

public event PropertyChangedEventHandler? PropertyChanged

Event Type

PropertyChangedEventHandler

PropertyChanging

Event that is called when a key is being changed

public event PropertyChangingEventHandler? PropertyChanging

Event Type

PropertyChangingEventHandler