title: Overriding "if" statement in NCalc
body: <p>I am struggling to understand the NCalc and I have few questions.</p>
  
  <p>1) If I have an expression like "if(CLOSE&lt;2.3,ROC(OPEN),HIGH)" and ROC is a custom function. Does the result of "ROC(OPEN)" is available when the condition "CLOSE&lt;2.3" is being evaluated?</p>
  
  <p>2) How do I override the "If" statement? For the case below, I would like to perform a conditional check on each element in "listOpen". If the condition evaluated TRUE then I need to return the value at index where the condition was evaluated true from "listROC" otherwise return  the value at the same index from listHigh.</p>
  
  <p>example :</p>
  
  <pre><code>List&lt;double&gt; listResult =  new List&lt;double&gt;();
  for(int index = 0; index&lt; listClose.count;index++)
  {
      if(listClose[index]&lt;2.3)
           listResult.Add(listROC[index]);
      else
           listResult.Add(listHigh[index]);
  
  }
  
  return listResult;
  </code></pre>
  
  <p>This is sample code I am trying to get the expression evaluated. I am stuck at overriding/defining a custom if statement.</p>
  
  <pre><code>    private List&lt;double&gt; listOpen = new List&lt;double&gt;();
      private List&lt;double&gt; listClose = new List&lt;double&gt;();
      private List&lt;double&gt; listHigh = new List&lt;double&gt;();
      public void PrepareData()
      {
          for (int index = 0; index &lt; 10; index++)
          {
              Random rnd = new Random();
              double open = rnd.NextDouble() * (2.5 - 2.0) + 2.0;
              listOpen.Add(open);
              double close = rnd.NextDouble() * (2.5 - 2.0) + 2.0;
              listClose.Add(close);
              double high = rnd.NextDouble() * (2.5 - 2.0) + 2.0;
              listHigh.Add(high);
  
          }
      }
      private void EvaluateExpression()
      {
          PrepareData();
  
          Expression ex = new Expression("if(CLOSE&lt;2.3,ROC(OPEN),HIGH)");
          ex.EvaluateFunction += delegate(string name, FunctionArgs args)
          {
              if (name == "ROC")
              {
                  List&lt;double&gt; listROC = new List&lt;double&gt;();
                  string argument = args.Parameters[0].Evaluate().ToString();
                  List&lt;double&gt; listParam = new List&lt;double&gt;();
                  switch (argument)
                  {
                      case "OPEN":
                          listParam = listOpen;
                          break;
                      case "CLOSE":
                          listParam = listClose;
                          break;
                      case "HIGH":
                          listParam = listHigh;
                          break;
                  }
                  foreach (double dbl in listParam)
                  {
                      double result = dbl * 2;
                      listROC.Add(result);
                  }
                  args.Result = listROC;
              }
              if (name == "if")
              {
                 //Override the if function
              }
          };
  
          object ob = ex.Evaluate();
      }
  </code></pre>
  
  <p>Any help is much appreciated.</p>