public IPredicateVisitor Convert(Expression expression, IPredicateVisitorFactory predicateVisitorFactory) { MethodCallExpression methodCallExpression = expression as MethodCallExpression; if (methodCallExpression == null) { return(null); } string methodName = Mapping.AllowedMethods[methodCallExpression.Method.Name]; var memberExpression = methodCallExpression.Arguments[0] as MemberExpression; string currentName = memberExpression.Member.Name; var callerParent = predicateVisitorFactory.Create(memberExpression.Expression); ConstantPredicateVisitor constant = new ConstantPredicateVisitor(currentName); // c.Key.In("c14", "c15") if (methodCallExpression.Arguments.Count > 1) { IPredicateVisitor methodArguments = predicateVisitorFactory.Create(methodCallExpression.Arguments[1]); var inner = new BinaryPredicateVisitor(constant, methodName, methodArguments); return(CombinePredicates(callerParent, inner)); } // c.Key.IsDefined() var binaryPredicateVisitor = new BinaryPredicateVisitor(constant, methodName, new ConstantPredicateVisitor(string.Empty)); return(CombinePredicates(callerParent, binaryPredicateVisitor)); }
public IPredicateVisitor Convert(Expression expression, IPredicateVisitorFactory predicateVisitorFactory) { MethodCallExpression methodCallExpression = expression as MethodCallExpression; if (methodCallExpression == null) { return(null); } string methodName = FilterMapping.AllowedGroupMethods[methodCallExpression.Method.Name]; ConstantPredicateVisitor method = new ConstantPredicateVisitor(methodName); IPredicateVisitor parent = predicateVisitorFactory.Create(methodCallExpression.Arguments[0]); List <IPredicateVisitor> parameters = new List <IPredicateVisitor>(); if (methodCallExpression.Arguments[1].NodeType != ExpressionType.NewArrayInit) { return(null); } foreach (Expression part in ((NewArrayExpression)methodCallExpression.Arguments[1]).Expressions) { parameters.Add(predicateVisitorFactory.Create(part)); } CollectionPredicateVisitor collection = new CollectionPredicateVisitor(parameters); EqualPredicateVisitor equal = new EqualPredicateVisitor(method, collection); Visitors.AccessorPredicateVisitor accessor = new Visitors.AccessorPredicateVisitor(equal, parent); return(accessor); }
private static IPredicateVisitor RemoveQuotes(IPredicateVisitor inner) { if (inner is ConstantPredicateVisitor constantVisitor) { ConstantPredicateVisitor constantWithoutQuotes = new ConstantPredicateVisitor(constantVisitor.Constant.RemoveQuotes(), true); return(constantWithoutQuotes); } return(inner); }
/// <summary> /// Remove Quotes and make it constant predicate visitor with case sensitive /// Attribute names must be case sensitive /// </summary> /// <param name="inner">The inner Constant Predicate Visitor</param> /// <returns>Constant Predicate Visitor</returns> private static IPredicateVisitor RemoveQuotesWithCaseSensitive(IPredicateVisitor inner) { if (inner is ConstantPredicateVisitor constantVisitor) { ConstantPredicateVisitor constantWithoutQuotes = new ConstantPredicateVisitor(constantVisitor.Constant.RemoveQuotes().WrapInBackticksIfNeeded(), true); return(constantWithoutQuotes); } return(inner); }
private static bool ArePropertiesEqual(ContainerPredicateVisitor left, ContainerPredicateVisitor right) { ConstantPredicateVisitor constantLeft = left.Parent as ConstantPredicateVisitor; ConstantPredicateVisitor constantRight = right.Parent as ConstantPredicateVisitor; if (constantLeft != null && constantRight != null) { return(constantLeft.Constant == constantRight.Constant); } return(false); }
public IPredicateVisitor Convert(Expression expression, IPredicateVisitorFactory predicateVisitorFactory) { UnaryExpression unaryExpression = expression as UnaryExpression; if (unaryExpression == null) { return(null); } // c.Key == "c14" IPredicateVisitor inner = predicateVisitorFactory.Create(unaryExpression.Operand); ConstantPredicateVisitor not = new ConstantPredicateVisitor(Mapping.Not); return(new ContainerPredicateVisitor(inner, not)); }
public IPredicateVisitor Convert(Expression expression, IPredicateVisitorFactory predicateVisitorFactory) { MethodCallExpression methodCallExpression = expression as MethodCallExpression; if (methodCallExpression == null) { return(null); } string methodName = FilterMapping.AllowedMethods[methodCallExpression.Method.Name]; ConstantPredicateVisitor method = new ConstantPredicateVisitor(methodName); IPredicateVisitor parent = predicateVisitorFactory.Create(methodCallExpression.Arguments[0]); return(new EqualPredicateVisitor(parent, method)); }
public IPredicateVisitor Convert(Expression expression, IPredicateVisitorFactory predicateVisitorFactory) { MemberExpression memberExpression = expression as MemberExpression; if (memberExpression == null) { return(null); } // Id string currentName = memberExpression.Member.Name; ConstantPredicateVisitor constant = new ConstantPredicateVisitor(currentName); // c.Parent IPredicateVisitor parent = predicateVisitorFactory.Create(memberExpression.Expression); return(new ContainerPredicateVisitor(constant, parent)); }
public IPredicateVisitor Convert(Expression expression, IPredicateVisitorFactory predicateVisitorFactory) { if (expression is MethodCallExpression methodCallExpression) { string currentName = methodCallExpression.Method.Name; string currentAccessor = ParseMethodAccessorName(currentName); if (string.IsNullOrEmpty(currentAccessor)) { return(predicateVisitorFactory.Create(methodCallExpression.Arguments[0])); } AccessorPredicateVisitor parentAccessor = predicateVisitorFactory.Create(methodCallExpression.Arguments[0]) as AccessorPredicateVisitor; ConstantPredicateVisitor constantPredicateVisitor = new ConstantPredicateVisitor(currentAccessor); return(new AccessorPredicateVisitor(constantPredicateVisitor, parentAccessor)); } throw new NotSupportedException(); }
public IPredicateVisitor Convert(Expression expression, IPredicateVisitorFactory predicateVisitorFactory) { MethodCallExpression methodCallExpression = expression as MethodCallExpression; if (methodCallExpression == null) { return(null); } string methodName = this.AllowedMethods[methodCallExpression.Method.Name]; ConstantPredicateVisitor methodNameConstant = new ConstantPredicateVisitor(methodName); IPredicateVisitor methodCaller = predicateVisitorFactory.Create(methodCallExpression.Arguments[0]); IPredicateVisitor methodArguments = predicateVisitorFactory.Create(methodCallExpression.Arguments[1]); ContainerPredicateVisitor container = new ContainerPredicateVisitor(methodArguments, methodNameConstant, true); BinaryPredicateVisitor binary = new BinaryPredicateVisitor(methodCaller, string.Empty, container); return(binary); }
public IPredicateVisitor Convert(Expression expression, IPredicateVisitorFactory predicateVisitorFactory) { MethodCallExpression methodCallExpression = expression as MethodCallExpression; if (methodCallExpression == null) { return(null); } IPredicateVisitor inner = predicateVisitorFactory.Create(methodCallExpression.Arguments[1]); var memberExpression = methodCallExpression.Arguments[0] as MemberExpression; // Id string currentName = memberExpression.Member.Name; ConstantPredicateVisitor constant = new ConstantPredicateVisitor(currentName); IPredicateVisitor parent = predicateVisitorFactory.Create(memberExpression); return(CanBeCombined(parent) ? CombinePredicates(parent, inner) : new ContainerPredicateVisitor(inner, constant)); }
public IPredicateVisitor Convert(Expression expression, IPredicateVisitorFactory predicateVisitorFactory) { MemberExpression memberExpression = expression as MemberExpression; if (memberExpression == null) { return(null); } string currentName = memberExpression.Member.Name; if (FilterMapping.MembersToSkip.Contains(currentName)) { return(predicateVisitorFactory.Create(memberExpression.Expression)); } ConstantPredicateVisitor constant = new ConstantPredicateVisitor(currentName); IPredicateVisitor parent = predicateVisitorFactory.Create(memberExpression.Expression); return(new Visitors.AccessorPredicateVisitor(constant, parent)); }
public IPredicateVisitor Convert(Expression expression, IPredicateVisitorFactory predicateVisitorFactory) { var dynamicInvoke = Expression.Lambda(expression, null).Compile().DynamicInvoke(null); if (dynamicInvoke is DateTime dt) { return(new ConstantPredicateVisitor(dt.ToUtcIso8601().WrapInQuotes())); } if (dynamicInvoke is Enum enumResult) { return(new ConstantPredicateVisitor(enumResult.GetDescription().WrapInQuotes())); } if (dynamicInvoke.GetType().IsListOrArray()) { var array = dynamicInvoke as IEnumerable; var predicateVisitors = new List <IPredicateVisitor>(); if (array != null) { foreach (var item in array) { var visitor = new ConstantPredicateVisitor(item.ToString().WrapInQuotes()); predicateVisitors.Add(visitor); } } return(new CollectionPredicateVisitor(predicateVisitors)); } var compiledValue = dynamicInvoke.ToString(); if ((expression as MethodCallExpression)?.Arguments[0].Type == typeof(string)) { compiledValue = compiledValue.WrapInQuotes(); } return(new ConstantPredicateVisitor(compiledValue)); }