ComplexDictionary<TKey, TValue>
Namespace: Murder.Serialization
Assembly: Murder.dll
public class ComplexDictionary<TKey, TValue> : Dictionary<TKey, TValue>, IDictionary<TKey, TValue>, ICollection<T>, IEnumerable<T>, IEnumerable, IDictionary, ICollection, IReadOnlyDictionary<TKey, TValue>, IReadOnlyCollection<T>, ISerializable, IDeserializationCallback
When serializing dictionaries, System.Text.Json is not able to resolve custom dictionary keys. As a workaround for that, we will implement our own complex dictionary converter that manually deserializes each key and value.
Implements: Dictionary<TKey, TValue>, IDictionary<TKey, TValue>, ICollection<T>, IEnumerable<T>, IEnumerable, IDictionary, ICollection, IReadOnlyDictionary<TKey, TValue>, IReadOnlyCollection<T>, ISerializable, IDeserializationCallback
⭐ Constructors
public ComplexDictionary<TKey, TValue>()
public ComplexDictionary<TKey, TValue>(IDictionary<TKey, TValue> dictionary)
Parameters
dictionary
IDictionary<TKey, TValue>
public ComplexDictionary<TKey, TValue>(IEqualityComparer<T> comparer)
Parameters
comparer
IEqualityComparer<T>
⭐ Properties
Comparer
public IEqualityComparer<T> Comparer { get; }
Returns
IEqualityComparer<T>
Count
public virtual int Count { get; }
Returns
int
Item
public virtual TValue Item { get; public set; }
Returns
TValue
Keys
public KeyCollection<TKey, TValue> Keys { get; }
Returns
KeyCollection<TKey, TValue>
Values
public ValueCollection<TKey, TValue> Values { get; }
Returns
ValueCollection<TKey, TValue>
⭐ Methods
ContainsValue(TValue)
public bool ContainsValue(TValue value)
Parameters
value
TValue
Returns
bool
Remove(TKey, out TValue&)
public bool Remove(TKey key, TValue& value)
Parameters
key
TKey
value
TValue&
Returns
bool
TryAdd(TKey, TValue)
public bool TryAdd(TKey key, TValue value)
Parameters
key
TKey
value
TValue
Returns
bool
GetEnumerator()
public Enumerator<TKey, TValue> GetEnumerator()
Returns
Enumerator<TKey, TValue>
EnsureCapacity(int)
public int EnsureCapacity(int capacity)
Parameters
capacity
int
Returns
int
ContainsKey(TKey)
public virtual bool ContainsKey(TKey key)
Parameters
key
TKey
Returns
bool
Remove(TKey)
public virtual bool Remove(TKey key)
Parameters
key
TKey
Returns
bool
TryGetValue(TKey, out TValue&)
public virtual bool TryGetValue(TKey key, TValue& value)
Parameters
key
TKey
value
TValue&
Returns
bool
Add(TKey, TValue)
public virtual void Add(TKey key, TValue value)
Parameters
key
TKey
value
TValue
Clear()
public virtual void Clear()
GetObjectData(SerializationInfo, StreamingContext)
public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
Parameters
info
SerializationInfo
context
StreamingContext
OnDeserialization(Object)
public virtual void OnDeserialization(Object sender)
Parameters
sender
Object
TrimExcess()
public void TrimExcess()
TrimExcess(int)
public void TrimExcess(int capacity)
Parameters
capacity
int
⚡