private void EvalItem ( TypeCreator typeCreator, Expression parameter, JObject jObject ) { var props = jObject.Properties() .ToDictionary(o => o.Name, o => o.Value); var left = props["name"]; var rule = props["rule"]; var right = props["value"]; var leftExpression = typeCreator.BuildProjection(parameter, (JArray)left, false); var rightExpression = default(IFieldExpression); if (right is JArray) { rightExpression = typeCreator.BuildProjection(parameter, (JArray)right, false); } else { rightExpression = new FieldExpression(Expression.Constant(right.Value <object>()), parameter); } }
public override void Boost ( TypeCreator typeCreator, Expression expression, JProperty property, IDictionary <string, IFieldExpression> fields ) { var parameter = GetParameter(fields, expression); var lastField = fields.LastOrDefault(); //if (lastField.Value != null && (parameter.Type.FullName.Contains("IQueryable") || parameter.Type.FullName.Contains("IEnumerable") || parameter.Type.FullName.Contains("ICollection"))) //{ // var fieldValue = CallMethod // ( // typeCreator, // parameter, // (JArray)property.Value, // SelectManyMethod, // createAnonymousProjection: false // ); // fields.Add(property.Name, fieldValue); //} //else //{ if (lastField.Value == null) { var queryType = typeof(IQueryable <>).MakeGenericType(parameter.Type); var queryTypeParameter = Expression.Parameter(queryType); var selectProjection = typeCreator.BuildProjection(parameter, (JArray)property.Value, false); var selectLambda = selectProjection.GetLambdaExpression(); var returnType = selectProjection.Expression.Type.GetGenericArguments().Single(); var selectCall = Expression.Call(typeof(Queryable), nameof(Queryable.SelectMany), new Type[] { parameter.Type, returnType }, queryTypeParameter, Expression.Quote(selectLambda)); var fieldValue = new FieldExpression(selectCall, queryTypeParameter); fields.Add(property.Name, fieldValue); } else { var selectProjection = typeCreator.BuildProjection(parameter, (JArray)property.Value, false); var selectLambda = selectProjection.GetLambdaExpression(); var returnType = selectProjection.Expression.Type.GetGenericArguments().Single(); var groupByCall = lastField.Value.Expression; var selectCall = Expression.Call(typeof(Queryable), nameof(Queryable.SelectMany), new Type[] { parameter.Type, returnType }, groupByCall, Expression.Quote(selectLambda)); var fieldValue = new FieldExpression(selectCall, parameter); fieldValue.Parameter = lastField.Value.Parameter; fields.Remove(lastField.Key); fields.Add(property.Name, fieldValue); } //} }
public override void Boost ( TypeCreator typeCreator, Expression expression, JProperty property, IDictionary <string, IFieldExpression> fields ) { var parameter = GetParameter(fields, expression); var lastField = fields.LastOrDefault(); if (lastField.Value == null) { var entityType = parameter.Type; var entityParameter = parameter; var asQueryableCall = parameter; if (parameter.Type.FullName.Contains("IQueryable") || parameter.Type.FullName.Contains("IEnumerable") || parameter.Type.FullName.Contains("ICollection")) { entityType = parameter.Type.GetGenericArguments().Last(); entityParameter = Expression.Parameter(entityType); asQueryableCall = AsQueryable(parameter); } else { var queryType = typeof(IQueryable <>).MakeGenericType(parameter.Type); parameter = Expression.Parameter(queryType); asQueryableCall = parameter; } var selectProjection = typeCreator.BuildProjection(entityParameter, (JArray)property.Value, false); var selectLambda = selectProjection.GetLambdaExpression(); var selectCall = Expression.Call(typeof(Queryable), nameof(Queryable.Select), new Type[] { entityType, selectLambda.Body.Type }, asQueryableCall, Expression.Quote(selectLambda)); var asEnumerableCall = Expression.Call(typeof(Enumerable), nameof(Enumerable.AsEnumerable), new Type[] { selectLambda.Body.Type }, selectCall); var fieldValue = new FieldExpression(asEnumerableCall, parameter); fields.Add(property.Name, fieldValue); } else { var selectProjection = typeCreator.BuildProjection(parameter, (JArray)property.Value, false); var selectLambda = selectProjection.GetLambdaExpression(); var groupByCall = lastField.Value.Expression; var selectCall = Expression.Call(typeof(Queryable), nameof(Queryable.Select), new Type[] { parameter.Type, selectLambda.Body.Type }, groupByCall, Expression.Quote(selectLambda)); var fieldValue = new FieldExpression(selectCall, parameter); fieldValue.Parameter = lastField.Value.Parameter; fields.Remove(lastField.Key); fields.Add(property.Name, fieldValue); } }
public override void Boost ( TypeCreator typeCreator, Expression expression, JProperty property, IDictionary <string, IFieldExpression> fields ) { var parameter = GetParameter(fields, expression); if (parameter.Type.FullName.Contains("IGrouping")) { var lastField = fields.LastOrDefault(); var entityType = parameter.Type.GetGenericArguments().Last(); var entityParameter = Expression.Parameter(entityType); var sumProjection = typeCreator.BuildProjection(entityParameter, (JArray)property.Value, false); var sumLamda = sumProjection.GetLambdaExpression(); var method = SumMethod1.MakeGenericMethod(entityType); if (lastField.Value == null) { var sumCall = Expression.Call(method, parameter, sumLamda); var fieldValue = new FieldExpression(sumCall, parameter); fields.Add(property.Name, fieldValue); } else { var groupByCall = lastField.Value.Expression; var sumCall = Expression.Call(method, parameter, sumLamda); var selectLambda = Expression.Lambda(sumCall, parameter as ParameterExpression); var selectCall = Expression.Call(typeof(Queryable), "Select", new Type[] { parameter.Type, selectLambda.Body.Type }, groupByCall, Expression.Quote(selectLambda)); var fieldValue = new FieldExpression(selectCall, lastField.Value.Parameter); fields.Remove(lastField.Key); fields.Add(property.Name, fieldValue); } } else { var fieldValue = CallMethod ( typeCreator, parameter, (JArray)property.Value, SumMethod2, createAnonymousProjection: false ); fields.Add(property.Name, fieldValue); } }
public override void Boost ( TypeCreator typeCreator, Expression expression, JProperty property, IDictionary <string, IFieldExpression> fields ) { var configuration = (JArray)property.Value; var jArray = new JArray(configuration.First()); var projection = typeCreator.BuildProjection(expression, jArray, false); var name = configuration.Last(); fields.Add ( name.ToString(), projection ); }
protected IFieldExpression CallMethod ( TypeCreator typeCreator, Expression parameter, JArray jArray, MethodInfo methodInfo, bool createAnonymousProjection ) { var projection = typeCreator.BuildProjection(parameter, jArray, createAnonymousProjection); var lambda = projection.GetLambdaExpression(); return(CallMethod ( typeCreator, parameter, lambda, methodInfo )); }
private static Expression GetRuleContainer(TypeCreator typeCreator, Dictionary <string, JToken> props, Type returnType) { var _fields = new Dictionary <string, IFieldExpression>(); var p = Expression.Parameter(returnType); var fieldExpression = typeCreator.BuildProjection(p, (JArray)props["args"], false); var rules = (JArray)props["rules"]; var _expression = GetRule(typeCreator, (JObject)rules.First(), returnType, fieldExpression); foreach (JObject rule in rules.Skip(1)) { var _props = rule.Properties() .ToDictionary(o => o.Name, o => o.Value); var __expression = GetRule(typeCreator, _props, returnType, fieldExpression); _expression = (Expression)ApplyOperandMethod .MakeGenericMethod(returnType) .Invoke(null, new object[] { props, _expression, __expression }); } return(_expression); }