示例#1
0
 protected Calculator(Calculator original, Cloner cloner) {
   cloner.RegisterClonedObject(original, this);
   if (original.tokens != null)
     tokens = original.tokens.ToList();
 }
 public void Modify(List<IRun> runs) {
   var calc = new Calculator { Formula = Formula };
   foreach (var run in runs) {
     var variables = new Dictionary<string, IItem>();
     foreach (var param in run.Parameters)
       variables[param.Key] = param.Value;
     foreach (var result in run.Results)
       variables[result.Key] = result.Value;
     try {
       var value = calc.GetValue(variables);
       if (value != null)
         run.Results[ResultName] = value;
       else
         run.Results.Remove(ResultName);
     } catch (Exception x) {
       throw new Exception(string.Format("Calculation failed at Run {0}", run.Name), x);
     }
   }
 }