title: Nested expressions from string
body: <p>I'm using VS 2015, C#, target framework 4.6.1 to develop a way to execute rule actions created by end users and stored in a database. The idea is to allow them to enter a string that represents a command like the following: <code>CompareDatesReturnGreater(date1 =&gt; PushDate(//HEADER/ProcessDate, 7, Sat: Sun, //START/Branch), date2 =&gt; SetToToday())</code></p>
  
  <p>I can easily get the CompareDatesReturnGreater method name by parsing the input but if there are nested calls it gets harder to parse out all the method calls with the proper parameters - not impossible, but harder.</p>
  
  <p>I found that the following method works - executes the nested calls, etc. - but I cannot see how to get from the string that represents those expressions to the actual expression.</p>
  
  <pre><code>    public string ExternalCall()
      {
          string result = string.Empty;
          string input = "CompareDatesReturnGreaterFromFunc(date1 =&gt; PushDate(//HEADER/ProcessDate, 7, Sat: Sun, //START/Branch), date2 =&gt; SetToToday())";
          List&lt;string&gt; commands = SplitCommand(input);
          MethodInfo mi = this.GetType().GetMethod(commands[0], BindingFlags.Instance | BindingFlags.NonPublic);
          List&lt;object&gt; miParams = new List&lt;object&gt;();
  
          Expression&lt;Func&lt;string, string&gt;&gt; f1 = date1 =&gt; PushDate("//HEADER/ProcessDate", "7", "Sat: Sun", "//START/Branch");
          miParams.Add(f1);
          Expression&lt;Func&lt;string, string&gt;&gt; f2 = date1 =&gt; SetToToday();
          miParams.Add(f2);
  
          result = (string)mi.Invoke(this, miParams.ToArray());
          return result;
      }
  </code></pre>
  
  <p>The method that is invoked accepts the expressions and uses those to create MethodCallExpressions. Those are used to call the final method to generate the result.</p>
  
  <pre><code>    public string CompareDatesReturnGreaterFromFunc(Expression&lt;Func&lt;string, string&gt;&gt; func1, Expression&lt;Func&lt;string, string&gt;&gt; func2)
      {
          string result = string.Empty;
          MethodCallExpression operation1 = (MethodCallExpression)func1.Body;
          string result1 = (string)Expression.Lambda(operation1).Compile().DynamicInvoke();
          MethodCallExpression operation2 = (MethodCallExpression)func2.Body;
          string result2 = (string)Expression.Lambda(operation2).Compile().DynamicInvoke();
          result = CompareDates(result1, result2, true);
          return result;
      }
  </code></pre>
  
  <p>I found the suggestions for use of the Roslyn package but could not get them installed correctly into VS 2015 for the targeted framework.</p>
  
  <p>Or is there a better way to accomplish this without using expressions?</p>