title: Dynamic Dictionary usage in C#
body: <p>I am using a Dynamic dictionary in C#. The problem I am facing is the behavior of TryGetMember which I am overriding in the dynamic dictionary class.</p>
  
  <p>Here's the code of dynamic dictionary. </p>
  
  <pre><code>class DynamicDictionary&lt;TValue&gt; : DynamicObject
  {
      private IDictionary&lt;string, TValue&gt; m_dictionary;
  
      public DynamicDictionary(IDictionary&lt;string, TValue&gt; a_dictionary)
      {
          m_dictionary = a_dictionary;
      }
  
      public override bool TryGetMember(GetMemberBinder a_binder, out object a_result)
      {
          bool returnValue = false;
  
          var key = a_binder.Name;
          if (m_dictionary.ContainsKey(key))
          {
              a_result = m_dictionary[key];
              returnValue = true;
          }
          else            
              a_result = null;
  
          return returnValue;
      }
  }
  </code></pre>
  
  <p>Here, TryGetMember will be called at runtime whenever we refer some key from outside, but it's strange that binder's Name member which always gives the key what we refer from outside, it always resolves the key name written as characters of alphabets.</p>
  
  <p>e.g. if the object of DynamicDictionary made as:</p>
  
  <pre><code>Dictionary&lt;string,List&lt;String&gt;&gt; dictionaryOfStringVsListOfStrings; 
  
  //here listOfStrings some strings list already populated with strings
  dictionaryOfStringVsListOfStrings.Add("Test", listOfStrings); 
  dynamic dynamicDictionary_01 = new 
      DynamicDictionary&lt;List&lt;String&gt;(dictionaryOfStringVsListOfStrings);
  
  string somekey = "Test";
  
  //will be resolve at runtime
  List&lt;String&gt; listOfStringsAsValue = dynamicDictionary_01.somekey 
  </code></pre>
  
  <p>Now what happens here is "somekey" will become the value of a_binder (i.e a_binder.Name="somekey"). It should be resolved as a_binder.Name = "Test"  and then from the dynamic dictionary it will locate listOfStrings against this key (i.e. actually "Test" but it resolves not the value but actual variable name as key).</p>
  
  <p>Is there a way around this?</p>