PeanutButter
|
Provides a Dictionary class which returns default values for unknown keys (like Python's defaultdict) More...
Public Member Functions | |
DefaultDictionary (DefaultDictionaryFlags flags) | |
Create the default dictionary with the default resolver (returning default(TValue)) and the provided flags. | |
DefaultDictionary () | |
Constructs a DefaultDictionary where missing key lookups return the default value for TValue. | |
DefaultDictionary (Func< TValue > defaultResolver) | |
Constructs a DefaultDictionary where missing key lookups return the value provided by the default resolver. | |
DefaultDictionary (Func< TValue > defaultResolver, DefaultDictionaryFlags flags) | |
Creates the default dictionary with the provided default resolver, optionally storing resolved defaults for later re-use. | |
DefaultDictionary (Func< TValue > defaultResolver, IEqualityComparer< TKey > keyComparer) | |
Creates the default dictionary with the provided default resolver and key comparer. | |
DefaultDictionary (Func< TValue > defaultResolver, IEqualityComparer< TKey > keyComparer, DefaultDictionaryFlags flags) | |
Creates the default dictionary with the provided resolver and key comparer, choosing to store (and re-serve) resolved defaults when storeResolvedDefaults is true. | |
DefaultDictionary (Func< TKey, TValue > smartResolver) | |
Constructs a DefaultDictionary where missing key lookups return the value provided by the default resolver. | |
IEnumerator< KeyValuePair< TKey, TValue > > | GetEnumerator () |
Gets an enumerator for known items in the dictionary. | |
void | Remove (object key) |
void | Add (KeyValuePair< TKey, TValue > item) |
Adds an item to the dictionary. | |
bool | Contains (object key) |
void | Add (object key, object value) |
void | Clear () |
Removes all known items from the dictionary -> NB: you'll still get default values! | |
bool | Contains (KeyValuePair< TKey, TValue > item) |
Searches for an item in the dictionary. | |
void | CopyTo (KeyValuePair< TKey, TValue >[] array, int arrayIndex) |
Copies known items to the target array. | |
bool | Remove (KeyValuePair< TKey, TValue > item) |
Removes an item from the dictionary. | |
void | CopyTo (Array array, int index) |
bool | ContainsKey (TKey key) |
Always returns true - if the key is "unknown" a default can still be provided. | |
void | Add (TKey key, TValue value) |
Adds an item by key, value to the dictionary. | |
bool | Remove (TKey key) |
Removes an item by key from the dictionary. | |
bool | TryGetValue (TKey key, out TValue value) |
Tries to get a known value for the key, falling back on the default value. |
Properties | |
IEqualityComparer< TKey > | Comparer [get] |
Always report as case- and culture- insensitive. | |
object | this[object key] [get, set] |
int | Count [get] |
Gives the count of known items in the dictionary. | |
object | SyncRoot = new() [get] |
bool | IsSynchronized [get] |
bool | IsReadOnly [get] |
Always returns false - DefaultDictionaries are writable! | |
bool | IsFixedSize [get] |
TValue | this[TKey key] [get, set] |
Index into the dictionary. | |
ICollection< TKey > | Keys [get] |
Returns a collection of all known keys. | |
ICollection< TValue > | Values [get] |
Returns a collection of all known values. |
Provides a Dictionary class which returns default values for unknown keys (like Python's defaultdict)
TKey | |
TValue |
void PeanutButter.Utils.Dictionaries.DefaultDictionary< TKey, TValue >.Add | ( | KeyValuePair< TKey, TValue > | item | ) |
Adds an item to the dictionary.
item | KeyValuePair to add |
void PeanutButter.Utils.Dictionaries.DefaultDictionary< TKey, TValue >.Add | ( | TKey | key, |
TValue | value ) |
Adds an item by key, value to the dictionary.
key | Key to add |
value | Value to add |
bool PeanutButter.Utils.Dictionaries.DefaultDictionary< TKey, TValue >.Contains | ( | KeyValuePair< TKey, TValue > | item | ) |
Searches for an item in the dictionary.
item | Item to search for |
bool PeanutButter.Utils.Dictionaries.DefaultDictionary< TKey, TValue >.ContainsKey | ( | TKey | key | ) |
Always returns true - if the key is "unknown" a default can still be provided.
key | Key to search for |
void PeanutButter.Utils.Dictionaries.DefaultDictionary< TKey, TValue >.CopyTo | ( | KeyValuePair< TKey, TValue >[] | array, |
int | arrayIndex ) |
Copies known items to the target array.
array | Array to copy to |
arrayIndex | position to start copying at |
PeanutButter.Utils.Dictionaries.DefaultDictionary< TKey, TValue >.DefaultDictionary | ( | DefaultDictionaryFlags | flags | ) |
Create the default dictionary with the default resolver (returning default(TValue)) and the provided flags.
flags |
PeanutButter.Utils.Dictionaries.DefaultDictionary< TKey, TValue >.DefaultDictionary | ( | Func< TKey, TValue > | smartResolver | ) |
Constructs a DefaultDictionary where missing key lookups return the value provided by the default resolver.
smartResolver |
PeanutButter.Utils.Dictionaries.DefaultDictionary< TKey, TValue >.DefaultDictionary | ( | Func< TValue > | defaultResolver | ) |
Constructs a DefaultDictionary where missing key lookups return the value provided by the default resolver.
defaultResolver |
PeanutButter.Utils.Dictionaries.DefaultDictionary< TKey, TValue >.DefaultDictionary | ( | Func< TValue > | defaultResolver, |
DefaultDictionaryFlags | flags ) |
Creates the default dictionary with the provided default resolver, optionally storing resolved defaults for later re-use.
defaultResolver | |
flags |
PeanutButter.Utils.Dictionaries.DefaultDictionary< TKey, TValue >.DefaultDictionary | ( | Func< TValue > | defaultResolver, |
IEqualityComparer< TKey > | keyComparer ) |
Creates the default dictionary with the provided default resolver and key comparer.
defaultResolver | |
keyComparer |
ArgumentNullException |
PeanutButter.Utils.Dictionaries.DefaultDictionary< TKey, TValue >.DefaultDictionary | ( | Func< TValue > | defaultResolver, |
IEqualityComparer< TKey > | keyComparer, | ||
DefaultDictionaryFlags | flags ) |
Creates the default dictionary with the provided resolver and key comparer, choosing to store (and re-serve) resolved defaults when storeResolvedDefaults is true.
defaultResolver | |
keyComparer | |
flags |
ArgumentNullException |
IEnumerator< KeyValuePair< TKey, TValue > > PeanutButter.Utils.Dictionaries.DefaultDictionary< TKey, TValue >.GetEnumerator | ( | ) |
Gets an enumerator for known items in the dictionary.
bool PeanutButter.Utils.Dictionaries.DefaultDictionary< TKey, TValue >.Remove | ( | KeyValuePair< TKey, TValue > | item | ) |
Removes an item from the dictionary.
item | Item to remove |
bool PeanutButter.Utils.Dictionaries.DefaultDictionary< TKey, TValue >.Remove | ( | TKey | key | ) |
Removes an item by key from the dictionary.
key | Key to remove |
bool PeanutButter.Utils.Dictionaries.DefaultDictionary< TKey, TValue >.TryGetValue | ( | TKey | key, |
out TValue | value ) |
Tries to get a known value for the key, falling back on the default value.
key | Key to look up |
value | (out) parameter containing looked up (or default) value |
|
getset |
Index into the dictionary.
key | Key to look up |