Class ModelDictionary<TValue>
Class for holding string keys and custom values
Implements
Inherited Members
Namespace: DuetAPI.ObjectModel
Assembly: DuetAPI.dll
Syntax
[JsonConverter(typeof(ModelDictionaryConverter))]
public sealed class ModelDictionary<TValue> : IDictionary<string, TValue>, ICollection<KeyValuePair<string, TValue>>, IEnumerable<KeyValuePair<string, TValue>>, IModelDictionary, IModelObject, ICloneable, IDictionary, ICollection, IEnumerable, INotifyPropertyChanged, INotifyPropertyChanging
Type Parameters
| Name | Description |
|---|---|
| TValue |
Remarks
Key names are NOT converted to camel-case (unlike regular class properties)
Constructors
ModelDictionary(bool)
Constructor of this class
Declaration
public ModelDictionary(bool nullRemovesItems)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | nullRemovesItems | Defines if setting items to null effectively removes them |
Properties
Count
Returns the number of items in this collection
Declaration
public int Count { get; }
Property Value
| Type | Description |
|---|---|
| int |
IsFixedSize
Whether this dictionary has a fixed size
Declaration
public bool IsFixedSize { get; }
Property Value
| Type | Description |
|---|---|
| bool |
IsReadOnly
Whether the dictionary is read-only
Declaration
public bool IsReadOnly { get; }
Property Value
| Type | Description |
|---|---|
| bool |
IsSynchronized
If this is thread-safe
Declaration
public bool IsSynchronized { get; }
Property Value
| Type | Description |
|---|---|
| bool |
this[object]
Basic index operator
Declaration
public object this[object key] { get; set; }
Parameters
| Type | Name | Description |
|---|---|---|
| object | key | Key object |
Property Value
| Type | Description |
|---|---|
| object | Value if found |
this[string]
Index operator
Declaration
public TValue this[string key] { get; set; }
Parameters
| Type | Name | Description |
|---|---|---|
| string | key | Key |
Property Value
| Type | Description |
|---|---|
| TValue | Value |
Keys
List of keys
Declaration
public ICollection<string> Keys { get; }
Property Value
| Type | Description |
|---|---|
| ICollection<string> |
NullRemovesItems
Flags if keys can be removed again by setting their value to null
Declaration
[JsonIgnore]
public bool NullRemovesItems { get; }
Property Value
| Type | Description |
|---|---|
| bool |
SyncRoot
Synchronization root
Declaration
public object SyncRoot { get; }
Property Value
| Type | Description |
|---|---|
| object |
Values
List of values
Declaration
public ICollection<TValue> Values { get; }
Property Value
| Type | Description |
|---|---|
| ICollection<TValue> |
Methods
Add(KeyValuePair<string, TValue>)
Add a new item
Declaration
public void Add(KeyValuePair<string, TValue> item)
Parameters
| Type | Name | Description |
|---|---|---|
| KeyValuePair<string, TValue> | item | Item to add |
Add(object, object?)
Add a new item
Declaration
public void Add(object key, object? value)
Parameters
| Type | Name | Description |
|---|---|---|
| object | key | Key to add |
| object | value | Value to add |
Add(string, TValue)
Add a new item
Declaration
public void Add(string key, TValue value)
Parameters
| Type | Name | Description |
|---|---|---|
| string | key | Key to add |
| TValue | value | Value to add |
Assign(object)
Assign the properties from another instance
Declaration
public void Assign(object from)
Parameters
| Type | Name | Description |
|---|---|---|
| object | from | Other instance |
Clear()
Clear this dictionary
Declaration
public void Clear()
Clone()
Create a clone of this instance
Declaration
public object Clone()
Returns
| Type | Description |
|---|---|
| object |
Contains(KeyValuePair<string, TValue>)
Check if a key-value pair exists
Declaration
public bool Contains(KeyValuePair<string, TValue> item)
Parameters
| Type | Name | Description |
|---|---|---|
| KeyValuePair<string, TValue> | item | Item to check |
Returns
| Type | Description |
|---|---|
| bool | If the item exists in the dictionary |
Contains(object)
Check if a key is present
Declaration
public bool Contains(object key)
Parameters
| Type | Name | Description |
|---|---|---|
| object | key | Key to check |
Returns
| Type | Description |
|---|---|
| bool | Whether the key is present |
ContainsKey(string)
Check if a key is present
Declaration
public bool ContainsKey(string key)
Parameters
| Type | Name | Description |
|---|---|---|
| string | key | Key to check |
Returns
| Type | Description |
|---|---|
| bool | Whether the key is present |
CopyTo(Array, int)
Copy this instance to another array
Declaration
public void CopyTo(Array array, int index)
Parameters
| Type | Name | Description |
|---|---|---|
| Array | array | Destination array |
| int | index | Start index |
CopyTo(KeyValuePair<string, TValue>[], int)
Copy this instance to another dictionary
Declaration
public void CopyTo(KeyValuePair<string, TValue>[] array, int arrayIndex)
Parameters
| Type | Name | Description |
|---|---|---|
| KeyValuePair<string, TValue>[] | array | Destination array |
| int | arrayIndex | Start iondex |
FindDifferences(IModelObject?)
Create a dictionary or list of all the differences between this instance and another. This method outputs own property values that differ from the other instance
Declaration
public object? FindDifferences(IModelObject? other)
Parameters
| Type | Name | Description |
|---|---|---|
| IModelObject | other | Other instance |
Returns
| Type | Description |
|---|---|
| object | Object differences or null if both instances are equal |
GetEnumerator()
Get an enumerator for this instance
Declaration
public IEnumerator<KeyValuePair<string, TValue>> GetEnumerator()
Returns
| Type | Description |
|---|---|
| IEnumerator<KeyValuePair<string, TValue>> | Enumerator instance |
Remove(KeyValuePair<string, TValue>)
Remove a key-value pair if applicable
Declaration
public bool Remove(KeyValuePair<string, TValue> item)
Parameters
| Type | Name | Description |
|---|---|---|
| KeyValuePair<string, TValue> | item | Item to remove |
Returns
| Type | Description |
|---|---|
| bool | If the key-value pair was present |
Remove(object)
Remove a key (only supported if NullRemovesItems is true)
Declaration
public void Remove(object key)
Parameters
| Type | Name | Description |
|---|---|---|
| object | key | Key to remove |
Remove(string)
Remove a key (only supported if NullRemovesItems is true)
Declaration
public bool Remove(string key)
Parameters
| Type | Name | Description |
|---|---|---|
| string | key | Key to remove |
Returns
| Type | Description |
|---|---|
| bool | Whether the key could be found |
TryGetValue(string, out TValue)
Try to get a value
Declaration
public bool TryGetValue(string key, out TValue value)
Parameters
| Type | Name | Description |
|---|---|---|
| string | key | Key to look up |
| TValue | value | Retrieved value |
Returns
| Type | Description |
|---|---|
| bool | Whether the key could be found |
UpdateFromJson(JsonElement, bool)
Update this instance from a given JSON element
Declaration
public IModelObject? UpdateFromJson(JsonElement jsonElement, bool ignoreSbcProperties)
Parameters
| Type | Name | Description |
|---|---|---|
| JsonElement | jsonElement | Element to update this intance from |
| bool | ignoreSbcProperties | Whether SBC properties are ignored |
Returns
| Type | Description |
|---|---|
| IModelObject | Updated instance |
Remarks
Accepts null as the JSON value to clear existing items
Exceptions
| Type | Condition |
|---|---|
| JsonException | Failed to deserialize data |
Events
DictionaryCleared
Event that is called when the entire directory is cleared. Only used if NullRemovesItems is false
Declaration
public event EventHandler? DictionaryCleared
Event Type
| Type | Description |
|---|---|
| EventHandler |
PropertyChanged
Event that is called when a key has been changed
Declaration
public event PropertyChangedEventHandler? PropertyChanged
Event Type
| Type | Description |
|---|---|
| PropertyChangedEventHandler |
PropertyChanging
Event that is called when a key is being changed
Declaration
public event PropertyChangingEventHandler? PropertyChanging
Event Type
| Type | Description |
|---|---|
| PropertyChangingEventHandler |