PeanutButter
Loading...
Searching...
No Matches
PeanutButter.Utils.Dictionaries.MergeDictionary< TKey, TValue > Class Template Reference

Provides a mechanism to merge multiple dictionaries into one Source dictionaries. More...

Inheritance diagram for PeanutButter.Utils.Dictionaries.MergeDictionary< TKey, TValue >:

Public Member Functions

 MergeDictionary (params IDictionary< TKey, TValue >[] layers)
 Construct MergeDictionary over other dictionaries.
IEnumerator< KeyValuePair< TKey, TValue > > GetEnumerator ()
 Gets an Enumerator for the KeyValuePairs in this merged dictionary, prioritised by the order of provided layers.
void Add (KeyValuePair< TKey, TValue > item)
 Will throw - MergeDictionary is read-only.
void Clear ()
 Will throw - MergeDictionary is read-only.
bool Contains (KeyValuePair< TKey, TValue > item)
 Returns true if any layer contains the provided item.
void CopyTo (KeyValuePair< TKey, TValue >[] array, int arrayIndex)
 Copies the prioritised items to the provided array from the given arrayIndex.
bool Remove (KeyValuePair< TKey, TValue > item)
 Will throw an exception - MergeDictionary is read-only.
bool ContainsKey (TKey key)
 Searches for the given key across all layers.
void Add (TKey key, TValue value)
 Will throw - MergeDictionaries are read-only.
bool Remove (TKey key)
 Will throw - MergeDictionaries are read-only.
bool TryGetValue (TKey key, out TValue value)
 Tries to get a value by key from the underlying layers.
void AppendLayer (IDictionary< TKey, TValue > layer)
 Append a layer to the collection.
void InsertLayer (IDictionary< TKey, TValue > layer)
 Insert a layer at the top of the stack.
void InsertLayer (int idx, IDictionary< TKey, TValue > layer)
 Insert a layer at the provided index - see LayerCount for the valid range.

Properties

IEqualityComparer< TKey > Comparer [get]
 Expose the first (or least-restrictive, for strings) key comparer.
int Count [get]
 Returns the count of distinct keys.
bool IsReadOnly [get]
 Will return true: MergeDictionaries are read-only.
TValue this[TKey key] [get, set]
 Index into the layers to find the highest-priority match for the provided key.
ICollection< TKey > Keys [get]
 Returns a collection of the distinct keys in all layers.
ICollection< TValue > Values [get]
 Returns a collection of ALL values in all layers.
int LayerCount [get]
 Reflects the number of layers in this merged dictionary.

Detailed Description

Provides a mechanism to merge multiple dictionaries into one Source dictionaries.

Template Parameters
TKey
TValue

Member Function Documentation

◆ Add() [1/2]

void PeanutButter.Utils.Dictionaries.MergeDictionary< TKey, TValue >.Add ( KeyValuePair< TKey, TValue > item)

Will throw - MergeDictionary is read-only.

Parameters
item
Exceptions
InvalidOperationException

◆ Add() [2/2]

void PeanutButter.Utils.Dictionaries.MergeDictionary< TKey, TValue >.Add ( TKey key,
TValue value )

Will throw - MergeDictionaries are read-only.

Parameters
key
value
Exceptions
InvalidOperationException

◆ AppendLayer()

void PeanutButter.Utils.Dictionaries.MergeDictionary< TKey, TValue >.AppendLayer ( IDictionary< TKey, TValue > layer)

Append a layer to the collection.

  • being the lowest layer, only values which are not overridden by a higher layer will reflect
Parameters
layer

◆ Clear()

void PeanutButter.Utils.Dictionaries.MergeDictionary< TKey, TValue >.Clear ( )

Will throw - MergeDictionary is read-only.

Exceptions
InvalidOperationException

◆ Contains()

bool PeanutButter.Utils.Dictionaries.MergeDictionary< TKey, TValue >.Contains ( KeyValuePair< TKey, TValue > item)

Returns true if any layer contains the provided item.

Parameters
itemItem to search for
Returns
True if found, False if not

◆ ContainsKey()

bool PeanutButter.Utils.Dictionaries.MergeDictionary< TKey, TValue >.ContainsKey ( TKey key)

Searches for the given key across all layers.

Parameters
keyKey to search for
Returns
True if found, False otherwise

◆ CopyTo()

void PeanutButter.Utils.Dictionaries.MergeDictionary< TKey, TValue >.CopyTo ( KeyValuePair< TKey, TValue >[] array,
int arrayIndex )

Copies the prioritised items to the provided array from the given arrayIndex.

Parameters
arrayTarget array to copy to
arrayIndexIndex to start copying at

◆ GetEnumerator()

IEnumerator< KeyValuePair< TKey, TValue > > PeanutButter.Utils.Dictionaries.MergeDictionary< TKey, TValue >.GetEnumerator ( )

Gets an Enumerator for the KeyValuePairs in this merged dictionary, prioritised by the order of provided layers.

Returns

◆ InsertLayer() [1/2]

void PeanutButter.Utils.Dictionaries.MergeDictionary< TKey, TValue >.InsertLayer ( IDictionary< TKey, TValue > layer)

Insert a layer at the top of the stack.

Parameters
layer

◆ InsertLayer() [2/2]

void PeanutButter.Utils.Dictionaries.MergeDictionary< TKey, TValue >.InsertLayer ( int idx,
IDictionary< TKey, TValue > layer )

Insert a layer at the provided index - see LayerCount for the valid range.

Parameters
idx
layer

◆ MergeDictionary()

PeanutButter.Utils.Dictionaries.MergeDictionary< TKey, TValue >.MergeDictionary ( params IDictionary< TKey, TValue >[] layers)

Construct MergeDictionary over other dictionaries.

Parameters
layers

◆ Remove() [1/2]

bool PeanutButter.Utils.Dictionaries.MergeDictionary< TKey, TValue >.Remove ( KeyValuePair< TKey, TValue > item)

Will throw an exception - MergeDictionary is read-only.

Parameters
itemItem to remove
Returns
Exceptions
InvalidOperationException

◆ Remove() [2/2]

bool PeanutButter.Utils.Dictionaries.MergeDictionary< TKey, TValue >.Remove ( TKey key)

Will throw - MergeDictionaries are read-only.

Parameters
key
Returns
Exceptions
InvalidOperationException

◆ TryGetValue()

bool PeanutButter.Utils.Dictionaries.MergeDictionary< TKey, TValue >.TryGetValue ( TKey key,
out TValue value )

Tries to get a value by key from the underlying layers.

Parameters
keyKey to search for
valueValue to search for
Returns
True if found, False otherwise

Property Documentation

◆ this[TKey key]

TValue PeanutButter.Utils.Dictionaries.MergeDictionary< TKey, TValue >.this[TKey key]
getset

Index into the layers to find the highest-priority match for the provided key.

Parameters
keyKey to look up

The documentation for this class was generated from the following file:
  • source/Utils/PeanutButter.Utils/Dictionaries/MergeDictionary.cs