Why doesn't HttpSessionState implement an IDictionary?

The HttpSessionState seems to be a typical collection of keys -> values, so why doesn't it implement the IDictionary - Interface?

Reference Information. I am trying to deduce / save the context of my ASP.NET website when an error occurs and want to do this using a recursive function that outputs the collection and all containing collections. Since the HttpSessionState implements only ICollection and IEnumerable , I lose the key information if I want to do it in a general way (= working with interfaces).

+6
source share
3 answers

IDictionary implies that the target collection is able to quickly search for a key. (As far as I know) HttpSessionState is just a list of elements, not a dictionary style structure. Since the search for this structure will take linear time, there is no reason to consider it as a dictionary. If you need a lot of quick searches, copy the keys and values ​​into a real dictionary. If you don't need fast search queries, you just need to specialize in this class.

There are more to the interface than just a list of prototype methods. There is semantics that must also be preserved for the interface. A quick key search is one such implicit assumption for (most) consumers of any IDictionary .

+7
source

How do I write my own wrapper implementation of IDictionary, which takes an HttpSessionState object in its constructor and behaves the way you want? I assume that you want to do this so that you can swap other types of name implementations (implementation of IDictionary implementation).

Of course, as Billy points out, this is a great way to put on a bad version of the psedyo dictionary in dictionary clothes!

+2
source

Simply navigate through the Session Keys and reference values ​​as follows:

 Session[key] 
-1
source

Source: https://habr.com/ru/post/893001/


All Articles