/// <summary> /// Create aggregation functions /// </summary> public static Expression Aggregate(this Expression me, AggregationFunctionType aggregation) { var aggregateMethod = typeof(Enumerable).GetGenericMethod(aggregation.ToString(), new Type[] { me.Type.GetTypeInfo().GenericTypeArguments[0] }, new Type[] { me.Type }); return(Expression.Call(aggregateMethod as MethodInfo, me)); }
public Aggregation Instantiate(ColumnType columnType, AggregationFunctionType function, IScalarResolver[] parameters, IAggregationStrategy[] strategies) { var missingValue = (IMissingValueStrategy)(strategies.SingleOrDefault(x => x is IMissingValueStrategy) ?? new DropStrategy(columnType)); var emptySeries = (IEmptySeriesStrategy)(strategies.SingleOrDefault(x => x is IEmptySeriesStrategy) ?? new ReturnDefaultStrategy(columnType)); var @namespace = $"{this.GetType().Namespace}.Function."; var typeName = $"{Enum.GetName(typeof(AggregationFunctionType), function)}{Enum.GetName(typeof(ColumnType), columnType)}"; var type = GetType().Assembly.GetType($"{@namespace}{typeName}", false, true) ?? throw new ArgumentException($"No aggregation named '{typeName}' has been found in the namespace '{@namespace}'."); if ((parameters?.Count() ?? 0) == 0) { return(new Aggregation((IAggregationFunction)(type.GetConstructor(Type.EmptyTypes).Invoke(Array.Empty <object>())), missingValue, emptySeries)); } else { var ctor = type.GetConstructors().Where(x => x.IsPublic && (x.GetParameters().Count() == parameters.Count())).FirstOrDefault() ?? throw new ArgumentException($"No public constructor for the aggregation '{function}' expecting {parameters.Count()} parameters."); return(new Aggregation((IAggregationFunction)ctor.Invoke(parameters), missingValue, emptySeries)); } }
public AggregationArgs(AggregationFunctionType function, ColumnType columnType, IList <IScalarResolver> parameters) => (ColumnType, Function, Parameters) = (columnType, function, parameters ?? new List <IScalarResolver>());
public void Instantiate_ColumnTypeAndAggregationFunction_CorrectAggregation(ColumnType columnType, AggregationFunctionType function) { var factory = new AggregationFactory(); Assert.Throws <ArgumentException>(() => factory.Instantiate(columnType, function, Array.Empty <IScalarResolver>(), Array.Empty <IAggregationStrategy>())); }
public void Instantiate_ColumnTypeandAggregationFunction_CorrectAggregation(ColumnType columnType, AggregationFunctionType function, Type expectedType) { var factory = new AggregationFactory(); var aggregation = factory.Instantiate(columnType, function, Array.Empty <IScalarResolver>(), Array.Empty <IAggregationStrategy>()); Assert.That(aggregation, Is.Not.Null); Assert.That(aggregation.Function, Is.TypeOf(expectedType)); }
public ColumnAggregationArgs(IColumnIdentifier identifier, AggregationFunctionType function, ColumnType columnType, IList <IScalarResolver> parameters) : base(function, columnType, parameters) => (Identifier) = (identifier);
public AggregationXml(AggregationFunctionType function) => Function = function;