title: C# evaluate a string expression and return the result
body: <p>Trying to figure out which approach to use in .net/C# to evaluate a simple expression in runtime. Code must be .net standard compliant, and I dont want  weird dependecies.</p>
  
  <p>I have looked into using using Microsoft.CodeAnalysis.CSharp.Scripting:
  <a href="https://stackoverflow.com/questions/4629/how-can-i-evaluate-c-sharp-code-dynamically">How can I evaluate C# code dynamically?</a> but it seems overkill for my use case.</p>
  
  <pre><code>public class Evaluate
      {
          private Dictionary&lt;string, object&gt; _exampleVariables = new Dictionary&lt;string, object&gt;
          {
              {"x", 45},
              {"y", 0},
              {"z", true}
          };
          private string _exampleExpression = "x&gt;y || z";
          private string _exampleExpression2 = @"if(x&gt;y || z) return 10;else return 20;
  ";
          public object Calculate(Dictionary&lt;string, object&gt; variables, string expression)
          {
              var result = //Magical code
              return result;
          }
      }
  </code></pre>