Enhanced C#
Language of your choice: library documentation
Properties | Public Member Functions | List of all members
Loyc.Collections.IDictionarySink< in in K, in in V > Interface Template Reference

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


Source file:

Remarks

Represents a write-only dictionary class.

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).

Properties

this[K key] [set]
 

Public Member Functions

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