Wednesday, December 21, 2016

Tuple Dictionary Key ???

The other day myself and some coworkers where going over some ideas on refactoring a process.  In this conversation the idea of a dictionary key of a tuple came up.  I thought this has to work especially after my last post about dictionaries => Fun with Dictionaries – Replacing ugly switch and if statements

So below is some code showing my findings.  Also here is the link to my github with all the code (https://github.com/devdaves/FunWithDictionaries2)

Here is an example factory where the dictionary with a tuple key is instantiated and used.

Using the Tuple as a key you can actually take some extremely complicated logic with multiple options and turn it into a simple dictionary lookup.

No comments:

Post a Comment