title: Static(expression) alternative for type.GetFields()
body: <p>I'm trying to implement static reflection for all fields in the class. 
  In other words, I have to create get and set using name for all these fields. </p>
  
  <p>I use the answers on <a href="https://stackoverflow.com/questions/37188900/set-field-value-with-expression-tree">Set field value with Expression tree</a>, and came to the following solution</p>
  
  <pre><code>  public class ExpressionSetterGetter
      {
          public class SetterGetter&lt;T&gt; where T : class
          {
              public Delegate getter;
              public Action&lt;T, object&gt; setter;
          }
  
          public static Dictionary&lt;string, SetterGetter&lt;T&gt;&gt; GetFieldSetterGetterExpressions&lt;T&gt;() where T : class
          {
  
              var dic = new Dictionary&lt;string, SetterGetter&lt;T&gt;&gt;();
              SetterGetter&lt;T&gt; setterGetter;
  
              var type = typeof(T);
              var fields = type.GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
              foreach (var fieldInfo in fields)
              {
                  var targetExp = Expression.Parameter(type, "target");
                  var valueExp = Expression.Parameter(typeof(object), "value");
                  var fieldExp = Expression.Field(targetExp, fieldInfo);
                  var assignExp = Expression.Assign(fieldExp, Expression.Convert(valueExp, fieldExp.Type));
                  var fieldSetter = Expression.Lambda&lt;Action&lt;T, object&gt;&gt;(assignExp, targetExp, valueExp).Compile();
  
                  ParameterExpression objParm = Expression.Parameter(type, "obj");
                  MemberExpression fieldExpr = Expression.Field(objParm, fieldInfo.Name);
                  var fieldExprConverted = Expression.Convert(fieldExpr, typeof(object));
                  var fieldGetter = Expression.Lambda(fieldExprConverted, objParm).Compile();
  
                  setterGetter = new SetterGetter&lt;T&gt;() { setter = fieldSetter, getter = fieldGetter };
  
                  dic.Add(fieldInfo.Name, setterGetter);
              }
              return dic;
          }
      }
  </code></pre>
  
  <p>Now, I have these two issues.</p>
  
  <ol>
  <li><p>I use type.GetFields(), but MSDN says it is a reflection method.
  What means that the compiler doesn't know the type before runtime.
  Am I right? If it is correct, what is the reason to use the
  expression trees. As far as I know expression trees translate to the
  code at compile-time time, what means almost no additional costs.</p></li>
  <li><p>The same logic. What if I put as a parameter a list with name of
      fields what have to be wrapped. In other words, instead of
      type.GetFields() I simply put the names of fields as parameters.</p>
  
  <p><code>public static Dictionary&lt;string, SetterGetter&lt;T&gt;&gt; GetFieldSetterGetterExpressions&lt;T&gt;(IEnumerable&lt;string&gt; fieldNames</code>)</p></li>
  </ol>
  
  <p>Obviously, the list can be not known at compile-time. Again, how the CLR will react?</p>