title: Func to get the property instead of just the value
body: <p>Is it possible to input an object and a second parameter to a method so that the second parameter can be used (without using strings and reflection) to get the a property of the object and use the property to both read and write the value?</p>
  
  <p>I've written two methods below that I can use but each one has drawbacks. The first DoStuff is typesafe ("good") but it needs three parameters ("bad"). The second needs two parameters (optimal), but it is not typesafe ("bad") as it relies on a string to specify the property. Maybe there is some solution using <code>Expression</code> that I have not thought of?</p>
  
  <p>Background: The usecase is that I want to be able to "extend" the value of any object (in my case I have lists of objects from several object reposites and these objects may have serveral properties containing userids as strings. another repository conatins the users and I want add info about the user to the strings in the previous repositories)</p>
  
  <pre><code>public class Foo
  {
      public string Bar {get; set;}
  }
  
  void Main()
  {
      var x = new Foo { Bar = "hello" };
      Console.WriteLine(x.Bar); // prints "hello"
  
      // the second paramter (Func&lt;..&gt;) gets the value, the third parameter Action&lt;...&gt;) sets the value
      DoStuff(x, y =&gt; y.Bar, (z, val) =&gt; z.Bar = val);
      Console.WriteLine(x.Bar); // prints "hello  goodbye"
  
      // just one parameter to get the property, but I would like this to be more type safe, preferably a Func
      DoStuff2(x, nameof(x.Bar));
      Console.WriteLine(x.Bar); // prints "hello  goodbye again"
  }
  
  public void DoStuff&lt;T&gt;(
      T obj, 
      Func&lt;T, string&gt; getProp, 
      Action&lt;T, string&gt; setProp)
  {
      var x = getProp(obj);
      setProp(obj, x + " goodbye");
  }
  
  public void DoStuff2&lt;T&gt;(
      T obj, 
      string propName)
  {
      var propInfo = typeof(T).GetProperty(propName);
      var currValue = propInfo.GetValue(obj) as string;
      propInfo.SetValue(obj, currValue + " again");
  }
  </code></pre>