using Newtonsoft.Json.Converters;
private static string[] json = new string[]{@"{
""WorkflowName"": ""Average Earnings"",
""Name"": ""YrsInAverage"",
""RuleName"": ""Final Average earnings"",
""SuccessEvent"": ""AvergeEarnings"",
""ErrorMessage"": ""Final Average earnings rule failed."",
""ErrorType"": ""Error"",
""RuleExpressionType"": ""LambdaExpression"",
""Expression"": ""input1.earnings != null && input1.earnings.Count > 0 && YrsInAverage > 0"",
""Name"": ""OutputExpression"",
""Expression"": ""input1.earnings.Skip(input1.earnings.Count() - YrsInAverage).Average(x => x)""
""RuleName"": ""Best Average earnings"",
""SuccessEvent"": ""AvergeEarnings"",
""ErrorMessage"": ""Best Average earnings rule failed."",
""ErrorType"": ""Error"",
""RuleExpressionType"": ""LambdaExpression"",
""Expression"": ""input1.earnings != null && input1.earnings.Count > 0 && YrsInAverage > 0"",
""Name"": ""OutputExpression"",
""Expression"": ""input1.earnings.OrderByDescending(x => x).Take(YrsInAverage).Average(x => x)""
public static void Main()
var workflowRules = json;
var re = new RulesEngine.RulesEngine(workflowRules);
""workflows"": [""Eligibility"", ""Time to Retirement"", ""Average Earnings""],
""earnings"": [60000, 62000]
""workflows"": [""Eligibility"", ""Time to Retirement"", ""Average Earnings""],
""earnings"": [70000, 72000, 85000, 88000, 91000, 98000, 70000, 72000, 85000]
""workflows"": [""Eligibility"", ""Time to Retirement"", ""Average Earnings""],
""earnings"": [70000, 72000, 85000, 88000, 91000, 98000, 70000, 72000, 85000, 70000, 72000, 85000, 70000, 72000, 85000, 70000, 72000, 85000, 91000, 93000, 96000, 101000, 105000, 108000, 120000, 123000, 90000, 95000, 98000]
dynamic[] inputs = JsonConvert.DeserializeObject<ExpandoObject[]>(inputStr,new ExpandoObjectConverter());
foreach(var input in inputs){
Console.WriteLine("****");
var resultList = re.ExecuteAllRulesAsync("Average Earnings",input).Result;
foreach(var result in resultList){
Console.WriteLine($"Rule - {result.Rule.RuleName}, IsSuccess - {result.IsSuccess}, ExceptionMessage - {result.ExceptionMessage}");
Console.WriteLine($"ActionOutput - {result.ActionResult.Output}, ActionException - {result.ActionResult.Exception}");