title: Create dictionary with memberexpression as key
body: <p>I would like to create a cache for my objects and expressions. With the following code he runs true all the elements, after this he would be able to use the expression/object from the dictionary. Instead of doing this he adds the member expression again to the dictionary with the same object.</p>
  
  <p>Is it possible to create a dictionary with a member expression, what am I doing wrong here?</p>
  
  <pre><code>private static readonly IDictionary&lt;MemberExpression, object&gt; Cache = new Dictionary&lt;MemberExpression, object&gt;();
  private static Func&lt;TClass, TProperty&gt; GetCachedMemberFunction&lt;TClass, TProperty&gt;(
      Expression&lt;Func&lt;TClass, TProperty&gt;&gt; member)
  {
      Func&lt;TClass, TProperty&gt; func;
      var memberExpression = member.Body as MemberExpression;
      if (Cache.ContainsKey(memberExpression))
      {
          func = (Func&lt;TClass, TProperty&gt;)Cache[memberExpression];
      }
      else
      {
          func = member.Compile();
          Cache[memberExpression] = func;
      }
  
      return func;
  }
  </code></pre>
  
  <p>Note: As you can see from the code I would like to create a cache so I only need to the compile function once.</p>