c# - Guarantees on documented/implicitly documented/undocumented behavior -


looking @ concurrentdictionary documentation says following:

represents thread-safe collection of key/value pairs can accessed multiple threads concurrently.

now when reading makes me think can call method in concurrentdictionary api , thread safe...but meant include explicit implementations aswell, have guarantee?

my example if want atomic operation remove item concurrentdictionary if value value.

so can this:

var concurrentdictionary = new concurrentdictionary<string, string>(); concurrentdictionary.tryadd("hey", "ho");  ((icollection<keyvaluepair<string, string>>) concurrentdictionary).remove(new keyvaluepair<string, string>("hey", "ho")); 

now have looked in source code , operation both atomic , thread safe, fact not on concurrentdictionary api mean shouldn't use it...or maybe using collection shouldn't doing it.

i can take 1 step further , write following extension method:

public static boolean tryremove(this icollection<keyvaluepair<tkey, tvalue>> collection, tkey key, tvalue value) {     return collection.remove(new keyvaluepair<tkey, tvalue>(key, value)); } 

this appear in intellisense concurrentdictionary because implements icollection interface , many developers may not know untoward (if is?!)

edit: mean "implicitly documented" concurrentdictionary implements set of interfaces. it's documentation says thread safe doesn't state if methods listed on page implies operations on instance safe.

this question documented behavior. in general, can rely on documented behavior hold. other behavior can change @ time (at runtime, between runs of app, between framework patch levels, ...).

if can find reference in docs safe ok this.

if not, i'd careful in general. on other hand, concurrentdictionary core type , bcl team applies extreme compatibility standards work. i'd ok doing in production apps without being documented. incredibly careful not break callers between major framework versions.

because of compatibility guarantees , being core type i'd ok deriving knowledge source code.


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -