title: How to create a generic Property Accessor without using Reflection?
body: <p>How to create a generic Property Accessor without using Reflection?</p>
  
  <p>I'd like to create a generic property accessor class to be able to pass a property object to it then accessing that property value; getting and setting.</p>
  
  <p>I don't like to use Reflection just with Func and Action and lambda expressions.</p>
  
  <p>The problem with the below code is that it makes a copy of the property value and passes it over so it doesn't send the property reference actually whereas I'd like to be able to get and set the Number property of the Product object using the GenericPropertyAccessor class.</p>
  
  <pre><code>   static void Main(string[] args)
      {
          var product = new Product {Number = 1};
  
          var productNumberAccesstor = new GenericPropertyAccessor&lt;int&gt;(product.Number);
  
          productNumberAccesstor.Value = 23;
  
          Console.WriteLine(productNumberAccesstor.Value);
  
          Console.ReadLine();
      }
  }
  
  public class Product
  {
      public int Number { get; set; }
      public string Name { get; set; }
  }
  
  public class GenericPropertyAccessor&lt;T&gt;
  {
      private T _property;
  
      public GenericPropertyAccessor(T propertyExpression)
      {
          _property = propertyExpression;
      }
  
      public T Value
      {
          get
          {
              return Get(() =&gt; _property);
          }
          set
          {
              Set(valueInput =&gt; _property = valueInput , value);
          }
      }
  
      static T Get(Func&lt;T&gt; getFunc)
      {
          return getFunc();
      }
  
      static void Set(Action&lt;T&gt; setAction, T value)
      {
          setAction(value);
      }
  
  }
  </code></pre>
  
  <p>Basically, what should I pass to the constructor of GenericPropertyAccessor to enable this?</p>
  
  <p>I know one solution would be as below but is it possible to even simplify this further? Specially on the constructor of the GenericPropertyAccessor. Is it possible to move the lambda expressions to the class and only passing a kind of property reference.</p>
  
  <pre><code> class Program
      {
          static void Main(string[] args)
          {
              var product = new Product {Number = 1};
  
              var productNumberAccesstor = new GenericPropertyAccessor&lt;int&gt;(() =&gt; product.Number, value =&gt; product.Number = value);
  
              productNumberAccesstor.Value = 23;
  
              Console.WriteLine(productNumberAccesstor.Value);
  
              Console.ReadLine();
          }
      }
  
      public class Product
      {
          public int Number { get; set; }
      }
  
      public class GenericPropertyAccessor&lt;T&gt;
      {
          private readonly Func&lt;T&gt; _getFunc;
          private readonly Action&lt;T&gt; _setAction;
  
          public GenericPropertyAccessor(Func&lt;T&gt; getFunc, Action&lt;T&gt; setAction)
          {
              _getFunc = getFunc;
              _setAction = setAction;
          }
  
          public T Value
          {
              get
              {
                  return _getFunc();
              }
              set
              {
                  _setAction(value);
              }
          }
      }
  </code></pre>
  
  <p>I mean how to pass the "product.Number" expression inside the class?</p>