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
nullRemovesItemsboolDefines 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
IsFixedSize
Whether this dictionary has a fixed size
public bool IsFixedSize { get; }
Property Value
IsReadOnly
Whether the dictionary is read-only
public bool IsReadOnly { get; }
Property Value
IsSynchronized
If this is thread-safe
public bool IsSynchronized { get; }
Property Value
this[object]
Basic index operator
public object this[object key] { get; set; }
Parameters
keyobjectKey object
Property Value
- object
Value if found
this[string]
Index operator
public JsonElement? this[string key] { get; set; }
Parameters
keystringKey
Property Value
- JsonElement?
Value
Keys
List of keys
public ICollection<string> Keys { get; }
Property Value
NullRemovesItems
Flags if keys can be removed again by setting their value to null
[JsonIgnore]
public bool NullRemovesItems { get; }
Property Value
SyncRoot
Synchronization root
public object SyncRoot { get; }
Property Value
Values
List of values
public ICollection<JsonElement?> Values { get; }
Property Value
Methods
Add(KeyValuePair<string, JsonElement?>)
Add a new item
public void Add(KeyValuePair<string, JsonElement?> item)
Parameters
itemKeyValuePair<string, JsonElement?>Item to add
Add(object, object?)
Add a new item
public void Add(object key, object? value)
Parameters
Add(string, JsonElement?)
Add a new item
public void Add(string key, JsonElement? value)
Parameters
keystringKey to add
valueJsonElement?Value to add
Assign(IStaticModelObject)
Assign the properties from another instance
public void Assign(IStaticModelObject from)
Parameters
fromIStaticModelObjectOther instance
Clear()
Clear this dictionary
public void Clear()
Clone()
Create a clone of this instance
public object Clone()
Returns
Contains(KeyValuePair<string, JsonElement?>)
Check if a key-value pair exists
public bool Contains(KeyValuePair<string, JsonElement?> item)
Parameters
itemKeyValuePair<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
keyobjectKey to check
Returns
- bool
Whether the key is present
ContainsKey(string)
Check if a key is present
public bool ContainsKey(string key)
Parameters
keystringKey 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
CopyTo(KeyValuePair<string, JsonElement?>[], int)
Copy this instance to another dictionary
public void CopyTo(KeyValuePair<string, JsonElement?>[] array, int arrayIndex)
Parameters
arrayKeyValuePair<string, JsonElement?>[]Destination array
arrayIndexintStart 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
itemKeyValuePair<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
keyobjectKey to remove
Remove(string)
Remove a key (only supported if NullRemovesItems is true)
public bool Remove(string key)
Parameters
keystringKey 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
keystringKey to look up
valueJsonElement?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
jsonElementJsonElementElement to update this intance from
ignoreSbcPropertiesboolWhether 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
readerUtf8JsonReaderJSON reader
ignoreSbcPropertiesboolWhether 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
PropertyChanged
Event that is called when a key has been changed
public event PropertyChangedEventHandler? PropertyChanged
Event Type
PropertyChanging
Event that is called when a key is being changed
public event PropertyChangingEventHandler? PropertyChanging