internal void Add <TProperty>( List <QueryStepBuilderParameter <TProperty> > parameters, Action <QueryExecutionContext> contextAction, Dictionary <string, object> stepBagItems, bool skipConnectionEdgeCheck, Type overrideRepositoryWithType) { var step = new QueryStep { ContextAction = contextAction, Items = stepBagItems, OverrideRepositoryWithType = overrideRepositoryWithType, SkipConnectionEdgeCheck = skipConnectionEdgeCheck }; parameters.ForEach(parameter => { // The property access might be getting converted to object to match the func. // If so, get the operand and see if that's a member expression. MemberExpression memberExpression = parameter.Expression.Body as MemberExpression ?? (parameter.Expression.Body as UnaryExpression)?.Operand as MemberExpression; if (memberExpression != null) { // Find the member. var rawMemberExpression = memberExpression.ToString(); var depth = rawMemberExpression.Count(x => x == '.'); string path = depth > 1 ? rawMemberExpression.Substring(rawMemberExpression.IndexOf('.') + 1) : memberExpression.Member.Name; var accessor = TypeAccessor.Create(typeof(TProperty)); var member = accessor.GetMembers().ToList().Single(x => x.Name == (depth > 1 ? path.Substring(0, path.IndexOf('.')) : memberExpression.Member.Name)); var modelMember = new ModelMember(typeof(TProperty), accessor, member, false); var qp = new QueryParameter { MemberModel = modelMember }; if (parameter.Mapper == null) { Members.Add(modelMember); } else { qp.Mapper = ctx => parameter.Mapper(ctx.Context); } step.QueryParameters.Add(qp); } else { throw new ArgumentException("Expression provided is not a member expression."); } }); _querySteps.Add(step); }
internal void Add <TProperty>( List <Expression <Func <TProperty, object> > > expressions, Func <QueryExecutionContext, List <object> > mapper, Action <QueryExecutionContext> contextAction, Dictionary <string, object> stepBagItems) { var step = new QueryStep { ContextAction = contextAction, Mapper = mapper, Items = stepBagItems }; bool first = mapper != null; expressions.ForEach(expression => { // The property access might be getting converted to object to match the func. // If so, get the operand and see if that's a member expression. MemberExpression memberExpression = expression.Body as MemberExpression ?? (expression.Body as UnaryExpression)?.Operand as MemberExpression; if (memberExpression != null) { // Find the member. var rawMemberExpression = memberExpression.ToString(); var depth = rawMemberExpression.Count(x => x == '.'); string path = depth > 1 ? rawMemberExpression.Substring(rawMemberExpression.IndexOf('.') + 1) : memberExpression.Member.Name; var accessor = TypeAccessor.Create(typeof(TProperty)); var member = accessor.GetMembers().ToList().Single(x => x.Name == (depth > 1 ? path.Substring(0, path.IndexOf('.')) : memberExpression.Member.Name)); var modelMember = new ModelMember(typeof(TProperty), accessor, member, false); if (first) { first = false; } else { _modelMemberList.Add(modelMember); } step.QueryParameters.Add(new QueryParameter { MemberModel = modelMember }); } else { throw new ArgumentException("Expression provided is not a member expression."); } }); _querySteps.Add(step); }
private void Add(bool isOptional, Member member) { var modelMember = new ModelMember(typeof(TSource), _modelConvention.ModelType.GetTypeAccessor(), member, isOptional); Members.Add(modelMember); _queryStep.QueryParameters.Add(new QueryParameter { MemberModel = modelMember }); }
public static bool UseNullWhenOptional(this ModelMember modelMember) { if (modelMember.IsOptional) { var attr = modelMember.Member.GetAttribute(typeof(ModelFieldAttribute), false) as ModelFieldAttribute; return(attr != null && attr.UseNullWhenOptional); } return(false); }
public static ContextValue GetContextValue(this ResolveFieldContext <object> context, ModelMember modelMember) { var name = modelMember.Name; var contextValue = new ContextValue(); contextValue.SelectValues = context.SubFields.Select(x => CreateSelectValue(x.Value)).ToList(); var args = context.Arguments; if (args.ContainsKey(name)) { Dictionary <string, object> arg = (Dictionary <string, object>)args[name]; if (modelMember.IsGuid) { contextValue.Values = new List <object> { Guid.Parse(arg.First().Value.ToString()) }; } else { contextValue.Values = new List <object> { arg.First().Value }; } if (contextValue.Values == null) { throw new ArgumentNullException($"{name}.Value"); } string comparison = arg.First().Key; if (comparison == "equal") { contextValue.Comparison = Comparisons.Equal; return(contextValue); } if (comparison == "contains" && contextValue.GetFirstValue() is string) { contextValue.Comparison = Comparisons.StringContains; return(contextValue); } if (comparison == "startsWith" && contextValue.GetFirstValue() is string) { contextValue.Comparison = Comparisons.StringStartsWith; return(contextValue); } if (comparison == "endsWith" && contextValue.GetFirstValue() is string) { contextValue.Comparison = Comparisons.StringEndsWith; return(contextValue); } if (comparison == "notEqual" && ( contextValue.GetFirstValue() is int || contextValue.GetFirstValue() is DateTime)) { contextValue.Comparison = Comparisons.NotEqual; return(contextValue); } if (comparison == "greaterThan" && ( contextValue.GetFirstValue() is int || contextValue.GetFirstValue() is DateTime)) { contextValue.Comparison = Comparisons.GreaterThan; return(contextValue); } if (comparison == "greaterEqualThan" && ( contextValue.GetFirstValue() is int || contextValue.GetFirstValue() is DateTime)) { contextValue.Comparison = Comparisons.GreaterEqualThan; return(contextValue); } if (comparison == "lessThan" && ( contextValue.GetFirstValue() is int || contextValue.GetFirstValue() is DateTime)) { contextValue.Comparison = Comparisons.LessThan; return(contextValue); } if (comparison == "lessEqualThan" && ( contextValue.GetFirstValue() is int || contextValue.GetFirstValue() is DateTime)) { contextValue.Comparison = Comparisons.LessEqualThan; return(contextValue); } throw new NotImplementedException($"Comparison: {comparison} is not implemented for type {contextValue.GetFirstValue().GetType().Name}."); } return(contextValue); }