Skip to content
Permalink
Browse files

Make changes as per review feedback

  • Loading branch information...
a046 committed Feb 19, 2019
1 parent 8d6b01c commit bb58ab0c680e19e509a6ae09eb7024662ecad000
@@ -18,7 +18,7 @@ public interface IQueryBuilder
void GroupBy<TSource, TKey, TElement>(Expression<Func<TSource, TKey>> keySelector, Expression<Func<TSource, TElement>> elementSelector);
void Collect<TSource>();
void OrderBy<TSource, TKey>(Expression<Func<TSource, TKey>> keySelector, SortDirection sortDirection);
void Aggregate<TSource, TResult>(string name, IEnumerable<NamedLambdaExpression> expressionCollection);
void Aggregate<TSource, TResult>(string name, IEnumerable<NamedLambdaExpression> expressionCollection, Type customFactoryType);
void Aggregate<TSource, TResult>(string name, IEnumerable<KeyValuePair<string, LambdaExpression>> expressionCollection);
void Aggregate<TSource, TResult>(string name, IEnumerable<KeyValuePair<string, LambdaExpression>> expressionCollection, Type customFactoryType);
}
}
@@ -170,12 +170,12 @@ public void Collect<TSource>()
};
}

public void Aggregate<TSource, TResult>(string aggregateName, IEnumerable<NamedLambdaExpression> expressionCollection)
public void Aggregate<TSource, TResult>(string aggregateName, IEnumerable<KeyValuePair<string, LambdaExpression>> expressionCollection)
{
Aggregate<TSource, TResult>(aggregateName, expressionCollection, null);
}

public void Aggregate<TSource, TResult>(string aggregateName, IEnumerable<NamedLambdaExpression> expressionCollection, Type customFactoryType)
public void Aggregate<TSource, TResult>(string aggregateName, IEnumerable<KeyValuePair<string, LambdaExpression>> expressionCollection, Type customFactoryType)
{
var previousBuildAction = _buildAction;
_buildAction = name =>
@@ -189,11 +189,11 @@ public void Collect<TSource>()
var previousResult = previousBuildAction(null);
var sourceBuilder = previousResult.Pattern;

var rewrittenExpressionCollection = new List<NamedLambdaExpression>();
var rewrittenExpressionCollection = new List<KeyValuePair<string, LambdaExpression>>();
foreach (var item in expressionCollection)
{
var expression = sourceBuilder.DslPatternExpression(_symbolStack.Scope.Declarations, item.Expression);
rewrittenExpressionCollection.Add(new NamedLambdaExpression(item.Name, expression));
var expression = sourceBuilder.DslPatternExpression(_symbolStack.Scope.Declarations, item.Value);
rewrittenExpressionCollection.Add(new KeyValuePair<string, LambdaExpression>(item.Key, expression));
}

aggregateBuilder.Aggregator(aggregateName, rewrittenExpressionCollection, customFactoryType);
@@ -11,14 +11,14 @@ public class AggregateBuilder : RuleElementBuilder, IBuilder<AggregateElement>
{
private string _name;
private Type _resultType;
private readonly List<NamedLambdaExpression> _expressions = new List<NamedLambdaExpression>();
private readonly List<KeyValuePair<string, LambdaExpression>> _expressions = new List<KeyValuePair<string, LambdaExpression>>();
private Type _customFactoryType;
private IBuilder<PatternElement> _sourceBuilder;

/// <summary>
/// Initializes a new instance of the <see cref="AggregateBuilder"/>.
/// </summary>
public AggregateBuilder()
public AggregateBuilder()
{
}

@@ -37,7 +37,7 @@ public void ResultType(Type resultType)
/// <param name="name">Name of the aggregator.</param>
/// <param name="expressions">Named expressions used by the aggregator.</param>
/// <param name="customFactoryType">The type of the custom aggregate factory</param>
public void Aggregator(string name, IEnumerable<NamedLambdaExpression> expressions, Type customFactoryType = null)
public void Aggregator(string name, IEnumerable<KeyValuePair<string, LambdaExpression>> expressions, Type customFactoryType = null)
{
_name = name;
_expressions.AddRange(expressions);
@@ -60,7 +60,7 @@ public void Collect()
public void OrderBy(LambdaExpression keySelector, SortDirection sortDirection)
{
var expressionName = sortDirection == SortDirection.Ascending ? "KeySelectorAscending" : "KeySelectorDescending";
_expressions.Add(new NamedLambdaExpression(expressionName, keySelector));
_expressions.Add(CreateNamedLambdaExpression(expressionName, keySelector));
}

/// <summary>
@@ -71,8 +71,8 @@ public void OrderBy(LambdaExpression keySelector, SortDirection sortDirection)
public void GroupBy(LambdaExpression keySelector, LambdaExpression elementSelector)
{
_name = AggregateElement.GroupByName;
_expressions.Add(new NamedLambdaExpression("KeySelector", keySelector));
_expressions.Add(new NamedLambdaExpression("ElementSelector", elementSelector));
_expressions.Add(CreateNamedLambdaExpression("KeySelector", keySelector));
_expressions.Add(CreateNamedLambdaExpression("ElementSelector", elementSelector));
}

/// <summary>
@@ -82,7 +82,7 @@ public void GroupBy(LambdaExpression keySelector, LambdaExpression elementSelect
public void Project(LambdaExpression selector)
{
_name = AggregateElement.ProjectName;
_expressions.Add(new NamedLambdaExpression("Selector", selector));
_expressions.Add(CreateNamedLambdaExpression("Selector", selector));
}

/// <summary>
@@ -92,7 +92,7 @@ public void Project(LambdaExpression selector)
public void Flatten(LambdaExpression selector)
{
_name = AggregateElement.FlattenName;
_expressions.Add(new NamedLambdaExpression("Selector", selector));
_expressions.Add(CreateNamedLambdaExpression("Selector", selector));
}

/// <summary>
@@ -148,6 +148,11 @@ AggregateElement IBuilder<AggregateElement>.Build()
return aggregateElement;
}

private static KeyValuePair<string, LambdaExpression> CreateNamedLambdaExpression(string name, LambdaExpression lambdaExpression)
{
return new KeyValuePair<string, LambdaExpression>(name, lambdaExpression);
}

private void AssertSingleSource()
{
if (_sourceBuilder != null)
Oops, something went wrong.

0 comments on commit bb58ab0

Please sign in to comment.
You can’t perform that action at this time.