Exemple #1
0
        public void Process(LinkedList <Token> tokens, ParameterExpression paramExpression)
        {
            var current = tokens.First;

            while (current.Next != null)
            {
                if (canProcess(current.Next.Value.TokenValue))
                {
                    var propertyName = current.Value.TokenValue;

                    Expression   parameterExpression = paramExpression;
                    Expression   returnExpression    = null;
                    PropertyInfo propertyInfo        = null;
                    var          propertyType        = parameterExpression.Type;

                    var propertySegments = propertyName.Split('.');
                    var segmentCount     = propertySegments.Count();

                    for (int i = 0; i < segmentCount; i++)
                    {
                        var segment = propertySegments[i];

                        propertyInfo        = GetPropertyInfo(propertyType, segment);
                        parameterExpression = Expression.Property(parameterExpression, propertyInfo);
                        propertyType        = propertyInfo.PropertyType;

                        if (i != segmentCount - 1)
                        {
                            var notNullExpression = Expression.NotEqual(parameterExpression, Expression.Constant(null, typeof(object)));
                            returnExpression = AndAlso(returnExpression, notNullExpression);
                        }
                    }

                    var expressionValue = StripOuterSingleQuotes(current.Next.Next.Value.TokenValue);

                    var propValue       = ConvertValue(expressionValue, propertyInfo.PropertyType);
                    var rightExpression = Expression.Constant(propValue, propertyInfo.PropertyType);

                    var operationType   = current.Next.Value.TokenValue;
                    var valueExpression = _operators.OperatorExpression(operationType, parameterExpression, rightExpression);

                    if (current.Next.Value.IsNot)
                    {
                        valueExpression = Expression.Not(valueExpression);
                    }

                    returnExpression = AndAlso(returnExpression, valueExpression);
                    current.Next.Value.OperatorExpression = returnExpression;

                    tokens.Remove(current.Next.Next);
                    var next = current.Next;
                    tokens.Remove(current);
                    current = next;
                }
                else
                {
                    current = current.Next;
                }
            }
        }
        public void Process(LinkedList <Token> tokens, ParameterExpression paramExpression)
        {
            var current = tokens.First.Next;

            while (current != null && current.Next != null)
            {
                if (canProcess(current.Value.TokenValue))
                {
                    var tokenValue          = current.Value.TokenValue;
                    var leftExpression      = current.Previous.Value.OperatorExpression;
                    var rightExpression     = current.Next.Value.OperatorExpression;
                    var resultingExpression = _operators.OperatorExpression(tokenValue, leftExpression, rightExpression);

                    current.Value.OperatorExpression = resultingExpression;
                    current.Value.TokenValue         = string.Empty;
                    tokens.Remove(current.Previous);
                    tokens.Remove(current.Next);
                }

                current = current.Next;
            }
        }