private Expression FillUpdateProjection(MemberExpression node)
        {
            PocoColumn column;

            if (node.Expression == null || node.Expression.NodeType != ExpressionType.Parameter)
            {
                column = _pocoData.GetColumnByMemberName(_currentBindingName.Get());
                if (column == null)
                {
                    throw new InvalidOperationException("No mapping defined for member: " + node.Member.Name);
                }
                if (column.IsCounter)
                {
                    var value = CqlExpressionVisitor.GetClosureValue(node);
                    if (!(value is long || value is int))
                    {
                        throw new ArgumentException("Only Int64 and Int32 values are supported as counter increment of decrement values");
                    }
                    _projections.Add(Tuple.Create(column, value, ExpressionType.Increment));
                    return(node);
                }
                AddProjection(node, column);
                return(node);
            }
            column = _pocoData.GetColumnByMemberName(node.Member.Name);
            if (column == null)
            {
                throw new InvalidOperationException("No mapping defined for member: " + node.Member.Name);
            }
            _projections.Add(Tuple.Create(column, (object)column.ColumnName, ExpressionType.Assign));
            return(node);
        }
        private Expression FillCondition(MemberExpression node)
        {
            var condition = _conditions.Last();

            if (node.Expression == null || node.Expression.NodeType == ExpressionType.MemberAccess)
            {
                var val = CqlExpressionVisitor.GetClosureValue(node);
                condition.SetParameter(val);
                return(node);
            }
            if (node.Expression.NodeType == ExpressionType.Parameter)
            {
                var column = _pocoData.GetColumnByMemberName(node.Member.Name);
                if (column == null)
                {
                    throw new InvalidOperationException($"No mapping defined for member: {node.Member.Name}");
                }

                condition.SetColumn(column);
                if (column.ColumnType == typeof(bool))
                {
                    condition.SetOperator(ExpressionType.Equal);
                    // We are evaluating a boolean expression parameter, the value we are trying to match is true
                    condition.SetParameter(true);
                }
                return(node);
            }
            if (node.Expression.NodeType == ExpressionType.Constant)
            {
                var val = CqlExpressionVisitor.GetClosureValue(node);
                if (val is CqlToken)
                {
                    var tokenValues = (val as CqlToken).Values;
                    condition.SetFunctionName("token").AllowMultipleParameters();
                    foreach (var pk in tokenValues)
                    {
                        condition.SetParameter(pk);
                    }
                }
                else
                {
                    condition.SetParameter(val);
                }
                return(node);
            }
            return(node);
        }
        private static object GetFieldValue(MemberExpression node)
        {
            var fieldInfo = (FieldInfo)node.Member;

            if (node.Expression is MemberExpression)
            {
                // The field of a field instance
                var instance = CqlExpressionVisitor.GetClosureValue((MemberExpression)node.Expression);
                return(fieldInfo.GetValue(instance));
            }
            if (node.Expression == null)
            {
                // Static field
                return(fieldInfo.GetValue(null));
            }
            return(fieldInfo.GetValue(((ConstantExpression)node.Expression).Value));
        }
        private static object GetPropertyValue(MemberExpression node)
        {
            var propertyInfo = (PropertyInfo)node.Member;

            if (node.Expression == null)
            {
                return(propertyInfo.GetValue(null));
            }

            if (node.Expression is MemberExpression)
            {
                // Field property
                var instance = CqlExpressionVisitor.GetClosureValue((MemberExpression)node.Expression);
                return(propertyInfo.GetValue(instance, null));
            }
            // Current instance property
            return(propertyInfo.GetValue(((ConstantExpression)node.Expression).Value, null));
        }
        /// <summary>
        /// Tries to evaluate the current expression and add it as a projection
        /// </summary>
        private Expression AddProjection(Expression node, PocoColumn column = null)
        {
            object value;

            if (node is MemberExpression)
            {
                value = CqlExpressionVisitor.GetClosureValue((MemberExpression)node);
            }
            else
            {
                value = Expression.Lambda(node).Compile().DynamicInvoke();
            }
            if (column == null)
            {
                column = _pocoData.GetColumnByMemberName(_currentBindingName.Get());
                if (column == null)
                {
                    throw new CqlLinqNotSupportedException(node, _parsePhase.Get());
                }
            }
            _projections.Add(Tuple.Create(column, value, ExpressionType.Assign));
            return(node);
        }