Enhanced C#
Loyc library documentation
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events Pages
Public Member Functions | List of all members
Loyc.Collections.IDictionarySink< in K, in V > Interface Template Reference

Represents a write-only dictionary class. More...


Source file:
Inheritance diagram for Loyc.Collections.IDictionarySink< in K, in V >:
Loyc.Collections.IIndexedSink< in K, in V > Loyc.Collections.BDictionary< K, V > Loyc.Collections.DictionaryAsSink< K, V, Dict > Loyc.Collections.IDictionaryImpl< K, V > Loyc.Collections.Bijection< K1, K2 > Loyc.Collections.IDictionaryEx< K, V > Loyc.Collections.BDictionary< K, V > Loyc.Collections.IDictionaryExWithChangeEvents< K, V > Loyc.Collections.MMap< K, V >

Remarks

Represents a write-only dictionary class.

The extension method DictionaryExt.AsSink{K, V}(IDictionary{K, V}) adapts any IDictionary{K,V} to this interface.

The methods here are a subset of the methods of IDictionary, so that a class that already implements IDictionary can support this interface also just by adding it to the interface list. However, one of the reasons you might want to implement this interface is to provide an asynchronous dictionary writer (in which operations are completed at a later time). In this case, the sink (dictionary writer) doesn't know whether a given key exists in the dictionary at the time Add(K,V) or Remove(K) is called, so it cannot know whether to throw KeyAlreadyExistsException or return true or false. Such implementations should not throw that exception, and they should return true from Remove. The implementation might also be unable to quickly count the values in the collection, so there is no Count property.

Due to the above considerations, when Remove returns true, users of this interface should not assume that the collection actually did contain the specified key. However if it returns false, the collection definitely did not contain it.

This interface does not implement IAdd{KeyValuePair{K, V}} because it would defeat contravariance, because structs do not support variance (KeyValuePair is a struct).

Public Member Functions

void Add (K key, V value)
 
bool Remove (K key)
 
void Clear ()
 

Additional Inherited Members

- Properties inherited from Loyc.Collections.IIndexedSink< in K, in V >
this[K key] [set]