Exemplo n.º 1
0
        public static PropertyPath <TValue> Create <TValue>(Expression <Func <TValue> > propertyExpression)
        {
            var          path          = PropertyPathVisitor.GetPath(propertyExpression);
            var          propertyInfos = path.Cast <PropertyInfo>().ToArray();
            var          parts         = new PathProperty[propertyInfos.Length];
            PathProperty previous      = null;

            for (int i = 0; i < propertyInfos.Length; i++)
            {
                var propertyInfo = propertyInfos[i];
                var item         = new PathProperty(previous, propertyInfo);
                parts[i] = item;
                previous = item;
            }

            var constants = ConstantVisitor.GetConstants(propertyExpression);

            if (!constants.Any())
            {
                throw new ArgumentException("Expression contains no constants", nameof(propertyExpression));
            }

            //valuePath.Source = source;
            var source       = constants.Last().Value;
            var propertyPath = new PropertyPath(parts);

            return(new PropertyPath <TValue>(propertyPath, source));
        }
Exemplo n.º 2
0
        private static string SaltKey(Expression expression)
        {
            ConstantVisitor constantVisitor = new ConstantVisitor();

            constantVisitor.Visit(expression);
            var saltKey = constantVisitor.ValueBuilder.ToString();

            saltKey = $"{XxHashUnsafe.ComputeHash(saltKey):X}";
            return(saltKey);
        }
Exemplo n.º 3
0
        private SimpleDisequalities(SimpleDisequalities <Variable, Expression> original)
            : base(original)
        {
            decoder = original.decoder;
            encoder = original.encoder;

            evalConstant = original.evalConstant;

            testTrueVisitor  = original.testTrueVisitor;
            testFalseVisitor = original.testFalseVisitor;

            checkIfHoldsVisitor = original.checkIfHoldsVisitor;
        }
Exemplo n.º 4
0
        public async Task Should_parameterize_value()
        {
            List <EntityDto> dtos;
            string           username;

            using (var db = new ClientContext())
            {
                username = "******";
                var query = ProjectTo <EntityDto>(db.Entities, new { username });
                dtos = await query.ToListAsync();

                var constantVisitor = new ConstantVisitor();
                constantVisitor.Visit(query.Expression);
                constantVisitor.HasConstant.ShouldBeFalse();
                dtos.All(dto => dto.UserName == username).ShouldBeTrue();

                username = "******";
                query    = ProjectTo <EntityDto>(
                    db.Entities,
                    new Dictionary <string, object> {
                    { "username", username }
                }
                    );
                dtos = await query.ToListAsync();

                constantVisitor = new ConstantVisitor();
                constantVisitor.Visit(query.Expression);
                constantVisitor.HasConstant.ShouldBeTrue();
                dtos.All(dto => dto.UserName == username).ShouldBeTrue();

                username = "******";
                query    = db.Entities.Select(
                    e =>
                    new EntityDto
                {
                    Id       = e.Id,
                    Value    = e.Value,
                    UserName = username
                }
                    );
                dtos = await query.ToListAsync();

                dtos.All(dto => dto.UserName == username).ShouldBeTrue();
                constantVisitor = new ConstantVisitor();
                constantVisitor.Visit(query.Expression);
                constantVisitor.HasConstant.ShouldBeFalse();
            }
        }
Exemplo n.º 5
0
        /// <summary>
        ///   Construct a new domain
        /// </summary>
        public SimpleDisequalities(IExpressionDecoder <Variable, Expression> /*!*/ decoder,
                                   IExpressionEncoder <Variable, Expression> /*!*/ encoder)
        {
            this.decoder = decoder;
            this.encoder = encoder;

            evalConstant = new ConstantVisitor(decoder);

            testTrueVisitor  = new SimpleDisequalitiesTestTrueVisitor(this.decoder, evalConstant);
            testFalseVisitor = new SimpleDisequalitiesTestFalseVisitor(this.decoder);

            testTrueVisitor.FalseVisitor = testFalseVisitor;
            testFalseVisitor.TrueVisitor = testTrueVisitor;

            checkIfHoldsVisitor = new SimpleDisequalitiesCheckIfHoldsVisitor(this.decoder, evalConstant);
        }
Exemplo n.º 6
0
 public SimpleDisequalitiesCheckIfHoldsVisitor(IExpressionDecoder <Variable, Expression> decoder,
                                               ConstantVisitor evalConstant)
     : base(decoder)
 {
     this.evalConstant = evalConstant;
 }
Exemplo n.º 7
0
 /// <summary>
 /// Visits the children of the <see cref="T:System.Linq.Expressions.BinaryExpression"/>.
 /// </summary>
 /// <param name="node">The expression to visit.</param>
 /// <returns>
 /// The modified expression, if it or any subexpression was modified; otherwise, returns the original expression.
 /// </returns>
 protected override Expression VisitBinary(BinaryExpression node)
 {
     LeftPartVisitor lv=new LeftPartVisitor();
     lv.Visit(node.Left);
     ConstantVisitor cv=new ConstantVisitor();
     cv.Visit(node.Right);
     if(!cv.Visited)
         throw new ArgumentException("Cannot evaluate:"+node.Right);
     Action<Operation, object> setAction;
     if(_simplePropertySetters.TryGetValue(lv.Member.Name,out setAction))
     {
         setAction.Invoke(TranslateOperation(node.NodeType),cv.Value);
     }
     return node;
 }