Skip to main content
5 events
when toggle format what by license comment
Nov 2, 2018 at 11:59 comment added t3chb0t I'm still wondering why the key has to be a dictionary. A simple custom ISet as a compound-key would do too. If you are able to replace this with IConfigutionSetting later then it's probably already overengineered.
Nov 1, 2018 at 14:05 comment added JohnLBevan I could probably get away with a simpler hashing tactic based on the most likely settings's values' (i.e. the values most likely to differ between keys), but I'd wanted to make the solution general purpose. I guess another option to improve this would be to allow an argument to passed to the comparer's constructor allowing more targeted generation; i.e. so the hash code used could target one specific property if we expect only one setting's value to differ between each key, vs using the code above when we don't know where the differences are likely to occur.
Nov 1, 2018 at 14:01 comment added JohnLBevan My plan is to use it as a poor man's cache (i.e. for objects which are expensive to create, but share the application's lifetime). At some point I'd likely switch my cache key from IImmutableDictionary to some kind of IConfigutionSetting, allowing me to create more targetted configuration settings classes; but initially I just wanted to run up something quick and dirty for my immediate use case. As you say, the number of items in each key would be small; and also the number of items in the dictionary which uses this key.
Nov 1, 2018 at 13:15 comment added Pieter Witvoet I still can't say I like this whole approach. It's taking something efficient (dictionary lookups) and making it easy to use in an inefficient manner (repeatedly expensive hash-code generation and value comparison). Repeatedly, because despite the immutable nature of the key dictionaries, each GetHashCode call has to check all content again every time (oh, and what if that content is mutable?) I'm curious, what's the intended use-case for this? I guess it's only meant to be used with relatively small keys?
Nov 1, 2018 at 10:45 history answered JohnLBevan CC BY-SA 4.0