title: Update arbitrary member with only non null values
body: <p>I have two classes with no inheritance relationship (well, excepting being Object):</p>
  
  <pre><code>class A
  {
    Member1 m1;
    Member2 m2;
  }
  
  class B
  {
    Member1 m3;
    Member2 m4;
  }
  </code></pre>
  
  <p>Each member of a class is paierd with a member of the same arbitrary type in the other class, it might or might not have the same name, it can be null.
  I would like to do something like this:</p>
  
  <pre><code> if (b.m3 != null) a.m1 = b.m3;
  </code></pre>
  
  <p>just to update values that are not null, where <code>a</code> is an instance of class <code>A</code> and <code>b</code> is an instance of class <code>B</code>.
  The number of members to update might grow with time, I'd like some more general and elegant way to do the update, something to be used like this:</p>
  
  <pre><code>a.Update(d =&gt; d.m1, b.m3)
  </code></pre>
  
  <p>I have tried with an extension method:</p>
  
  <pre><code>public static void Update&lt;TSource, TKey&gt;(this TSource source, Func&lt;TSource, TKey&gt; key, TKey newValue)
   where TSource : A
  {
   if (newValue != null)
   {
    key(source) = newValue;
   }
  }
  </code></pre>
  
  <p>but there is clearly something wrong because I get an exception saying that the left-hand side of the the equality <code>key(source)</code> must be a variable.
  Any ideas?</p>