title: Dynamic Create Func<T,TR> C#
body: <p>I'm trying to create a dynamic lambda exp to filter some results on my list, but I can't figure out on how to create a dynamic func&lt;,></p>
  
  <pre><code>//Here I get the type of my object "Produto", but I can have other objects here...Like "Pedido" or another one.
  Type type = typeof(Produto);
  
  var param = Expression.Parameter(type, "arg");
  var propName = Expression.Property(param, "Codigo");
  var constP = Expression.Constant("123");
  
  var nameStartsWith = Expression.Call(
      propName,
      typeof(string).GetMethod("StartsWith", new[] { typeof(string) }),
      constP);
  
  //Here I have to instantiate my Func&lt;T, bool&gt;
  //I can't instantiate it with my variable "type" to use on my Where clausule.
  //I don't know how to do this in another way, to create my lambda.
  
  var WhereExp = Expression.Lambda&lt;Func&lt;type, bool&gt;&gt;(nameStartsWith, param);
  
  return _uow.produto.GetAll().AsQueryable().Where(WhereExp).ToList();
  </code></pre>