public DynamicDataAggregation GroupBy(object groupBy) { var groupByColumns = new List <string>(); var aggregationClauses = new AggregationClauseCollection <object>(); if (groupBy is ODataExpression groupByExpression) { groupByColumns.Add(groupByExpression.Reference); } else { var objectType = groupBy.GetType(); var declaredProperties = objectType.GetDeclaredProperties(); foreach (var property in declaredProperties) { var propertyValue = property.GetValueEx(groupBy); switch (propertyValue) { case ODataExpression oDataExpression: groupByColumns.Add(oDataExpression.Reference); break; case ValueTuple <string, ODataExpression> aggregatedProperty: aggregationClauses.Add(new AggregationClause <object>(property.Name, aggregatedProperty.Item2?.Reference, aggregatedProperty.Item1)); break; } } } _underlyingDataAggregationBuilder.Add(new GroupByClause <object>(groupByColumns, aggregationClauses)); return(this); }
public DynamicDataAggregation Aggregate(object aggregation) { var aggregationClauses = new AggregationClauseCollection <object>(); var objectType = aggregation.GetType(); var declaredProperties = objectType.GetDeclaredProperties(); foreach (var property in declaredProperties) { var propertyValue = property.GetValue(aggregation); if (propertyValue is ValueTuple <string, ODataExpression> aggregatedProperty) { aggregationClauses.Add(new AggregationClause <object>(property.Name, aggregatedProperty.Item2?.Reference, aggregatedProperty.Item1)); } } _underlyingDataAggregationBuilder.Add(aggregationClauses); return(this); }