private IAggregatorFactory BuildAggregatorFactory(ReteBuilderContext context, AggregateElement element) { IAggregatorFactory factory; switch (element.Name) { case AggregateElement.CollectName: factory = new CollectionAggregatorFactory(); break; case AggregateElement.GroupByName: factory = new GroupByAggregatorFactory(); break; case AggregateElement.ProjectName: factory = new ProjectionAggregatorFactory(); break; case AggregateElement.FlattenName: factory = new FlatteningAggregatorFactory(); break; default: throw new ArgumentException( $"Unrecognized aggregate element. Name={element.Name}"); } var compiledExpressions = CompileExpressions(context, element); factory.Compile(element, compiledExpressions); return(factory); }
private IAggregatorFactory BuildAggregatorFactory(ReteBuilderContext context, AggregateElement element) { IAggregatorFactory factory; switch (element.Name) { case AggregateElement.CollectName: factory = new CollectionAggregatorFactory(); break; case AggregateElement.GroupByName: factory = new GroupByAggregatorFactory(); break; case AggregateElement.ProjectName: factory = new ProjectionAggregatorFactory(); break; case AggregateElement.FlattenName: factory = new FlatteningAggregatorFactory(); break; default: factory = GetCustomFactory(element); break; } var compiledExpressions = CompileExpressions(context, element); factory.Compile(element, compiledExpressions); return(factory); }
/// <summary> /// Configure group by aggregator. /// </summary> /// <param name="keySelector">Key selection expressions.</param> /// <param name="elementSelector">Element selection expression.</param> /// <typeparam name="TSource">Type of source elements to aggregate.</typeparam> /// <typeparam name="TKey">Type of grouping key.</typeparam> /// <typeparam name="TElement">Type of grouping element.</typeparam> public void GroupBy <TSource, TKey, TElement>(Expression <Func <TSource, TKey> > keySelector, Expression <Func <TSource, TElement> > elementSelector) { var aggregateFactory = new GroupByAggregatorFactory <TSource, TKey, TElement>(keySelector.Compile(), elementSelector.Compile()); _expressions["KeySelector"] = keySelector; _expressions["ElementSelector"] = keySelector; AggregatorFactory(GroupByName, aggregateFactory); }