title: Is there a way to create a delegate to get and set values for a FieldInfo?
body: <p>For properties there are <code>GetGetMethod</code> and <code>GetSetMethod</code> so that I can do:</p>
  
  <pre><code>Getter = (Func&lt;S, T&gt;)Delegate.CreateDelegate(typeof(Func&lt;S, T&gt;), 
                                               propertyInfo.GetGetMethod());
  </code></pre>
  
  <p>and</p>
  
  <pre><code>Setter = (Action&lt;S, T&gt;)Delegate.CreateDelegate(typeof(Action&lt;S, T&gt;), 
                                                 propertyInfo.GetSetMethod());
  </code></pre>
  
  <p>But how do I go about <code>FieldInfo</code>s? </p>
  
  <p>I am not looking for delegates to <code>GetValue</code> and <code>SetValue</code> (which means I will be invoking reflection each time) </p>
  
  <pre><code>Getter = s =&gt; (T)fieldInfo.GetValue(s);
  Setter = (s, t) =&gt; (T)fieldInfo.SetValue(s, t);
  </code></pre>
  
  <p>but if there is a <code>CreateDelegate</code> approach here? <strong>I mean <a href="https://stackoverflow.com/questions/3807192/why-do-assignment-statements-return-a-value">since assignments return a value</a>, can I treat assignments like a method?</strong> If so is there a <code>MethodInfo</code> handle for it? In other words <strong>how do I pass the right <code>MethodInfo</code> of setting and getting a value from a member field to <code>CreateDelegate</code> method so that I get a delegate back with which I can read and write to fields directly?</strong></p>
  
  <pre><code>Getter = (Func&lt;S, T&gt;)Delegate.CreateDelegate(typeof(Func&lt;S, T&gt;), fieldInfo.??);
  Setter = (Action&lt;S, T&gt;)Delegate.CreateDelegate(typeof(Action&lt;S, T&gt;), fieldInfo.??);
  </code></pre>
  
  <p><em>I can build expression and compile it, but I am looking for something simpler. In the end I don't mind going the expression route if there is no answer for the asked question</em>, as shown below: </p>
  
  <pre><code>var instExp = Expression.Parameter(typeof(S));
  var fieldExp = Expression.Field(instExp, fieldInfo);
  Getter = Expression.Lambda&lt;Func&lt;S, T&gt;&gt;(fieldExp, instExp).Compile();
  if (!fieldInfo.IsInitOnly)
  {
      var valueExp = Expression.Parameter(typeof(T));
      Setter = Expression.Lambda&lt;Action&lt;S, T&gt;&gt;(Expression.Assign(fieldExp, valueExp), instExp, valueExp).Compile();
  }
  </code></pre>
  
  <p>Or am I after the nonexistent (since I have nowhere seen something like that yet) ? </p>