System.Linq.Expressions.ExpressionVisitor.Visit(System.Linq.Expressions.Expression)

Here are the examples of the csharp api System.Linq.Expressions.ExpressionVisitor.Visit(System.Linq.Expressions.Expression) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

856 Examples 7

19 Source : ExpressionResovle.cs
with Apache License 2.0
from 1448376744

public virtual string Resovle()
        {
            Visit(_expression);
            return _textBuilder.ToString();
        }

19 Source : DataFilterUtil.cs
with MIT License
from 2881099

public Expression Modify(Expression expression, ParameterExpression parameter) {
			this.parameter = parameter;
			return Visit(expression);
		}

19 Source : JoinClause.cs
with MIT License
from 71

protected internal override QueryClause VisitChildren(ExpressionVisitor visitor)
            => Update(visitor.VisitAndConvert(Variable, nameof(VisitChildren)), visitor.Visit(Enumerable), visitor.Visit(Left), visitor.Visit(Right));

19 Source : JoinIntoClause.cs
with MIT License
from 71

protected internal override QueryClause VisitChildren(ExpressionVisitor visitor)
            => Update(visitor.VisitAndConvert(Variable, nameof(VisitChildren)), visitor.Visit(Enumerable), visitor.Visit(Left), visitor.Visit(Right), visitor.VisitAndConvert(Group, nameof(VisitChildren)));

19 Source : SelectClause.cs
with MIT License
from 71

protected internal override QueryClause VisitChildren(ExpressionVisitor visitor)
            => Update(visitor.Visit(Selector));

19 Source : WhereClause.cs
with MIT License
from 71

protected internal override QueryClause VisitChildren(ExpressionVisitor visitor)
            => Update(visitor.Visit(Condition));

19 Source : ForEachExpression.cs
with MIT License
from 71

protected override Expression VisitChildren(ExpressionVisitor visitor)
            => Update(visitor.VisitAndConvert(Variable, nameof(ForEachExpression.VisitChildren)),
                      visitor.Visit(Enumerable), visitor.Visit(Body),
                      BreakLabel, ContinueLabel);

19 Source : WhileExpression.cs
with MIT License
from 71

protected override Expression VisitChildren(ExpressionVisitor visitor)
            => Update(visitor.Visit(Test), visitor.Visit(Body), ContinueLabel, BreakLabel);

19 Source : AsyncExpression.cs
with MIT License
from 71

protected override Expression VisitChildren(ExpressionVisitor visitor)
            => Update(visitor.Visit(Body));

19 Source : YieldExpression.cs
with MIT License
from 71

protected override Expression VisitChildren(ExpressionVisitor visitor)
            => Update(visitor.Visit(Expression));

19 Source : LockExpression.cs
with MIT License
from 71

protected override Expression VisitChildren(ExpressionVisitor visitor)
            => Update(visitor.Visit(Object), visitor.Visit(Body));

19 Source : FromClause.cs
with MIT License
from 71

protected internal override QueryClause VisitChildren(ExpressionVisitor visitor)
            => Update(visitor.VisitAndConvert(Variable, nameof(VisitChildren)), visitor.Visit(Enumerable));

19 Source : GroupByClause.cs
with MIT License
from 71

protected internal override QueryClause VisitChildren(ExpressionVisitor visitor)
            => Update(visitor.VisitAndConvert(Variable, nameof(VisitChildren)), visitor.Visit(Selector));

19 Source : GroupByIntoClause.cs
with MIT License
from 71

protected internal override QueryClause VisitChildren(ExpressionVisitor visitor)
            => Update(visitor.VisitAndConvert(Variable, nameof(VisitChildren)), visitor.Visit(Selector), visitor.VisitAndConvert(Group, nameof(VisitChildren)));

19 Source : IteratorExpression.cs
with MIT License
from 71

protected override Expression VisitChildren(ExpressionVisitor visitor)
            => Update(visitor.Visit(Iterator));

19 Source : LetClause.cs
with MIT License
from 71

protected internal override QueryClause VisitChildren(ExpressionVisitor visitor)
            => Update(visitor.VisitAndConvert(Variable, nameof(VisitChildren)), visitor.Visit(Expression));

19 Source : ForExpression.cs
with MIT License
from 71

protected override Expression VisitChildren(ExpressionVisitor visitor)
            => Update(visitor.VisitAndConvert(Variable, nameof(VisitChildren)),
                      visitor.Visit(Initializer), visitor.Visit(Test),
                      visitor.Visit(Step), visitor.Visit(Body),
                      BreakLabel, ContinueLabel);

19 Source : AwaitExpression.cs
with MIT License
from 71

protected override Expression VisitChildren(ExpressionVisitor visitor)
            => Update(visitor.Visit(Expression), Method);

19 Source : QueryExpression.Parser.cs
with MIT License
from 71

public override Expression Visit(Expression node)
        {
            if (node == null)
                return null;

            return base.Visit(node);
        }

19 Source : LinkedExpression.cs
with MIT License
from 71

protected override Expression Accept(ExpressionVisitor visitor) => visitor.Visit(Reduce());

19 Source : UsingExpression.cs
with MIT License
from 71

protected override Expression VisitChildren(ExpressionVisitor visitor)
            => Update(visitor.VisitAndConvert(Variable, nameof(VisitChildren)), visitor.Visit(Disposable), visitor.Visit(Body));

19 Source : TrackingExpressionVisitor.cs
with MIT License
from 71

public override Expression Visit(Expression node)
        {
            if (node == null)
                return null;

            if (Projector != null)
            {
                // Project things in here, to avoid traversing the tree multiple times
                // ReSharper disable once PossibleInvalidCastExceptionInForeachLoop
                foreach (ExpressionProjector projector in Projector.GetInvocationList())
                    node = projector(node);
            }

            node = node.ReduceExtensions();

            if (node is BlockExpression block)
                // Make sure we don't have smaller scopes that would break the variable replacedignements
                node = block.Update(Enumerable.Empty<ParameterExpression>(), block.Expressions);

            if (node is ParameterExpression variable && !Variables.Contains(variable) && !variable.IsreplacedignableTo<VirtualStateMachine>())
                // Keep track of variable
                Variables.Add(variable);

            if (node.NodeType == ExpressionType.Extension && !node.CanReduce)
                // In case we're returning a special expression (ie: YieldExpression)
                return node;

            return base.Visit(node);
        }

19 Source : ExpressionPipeline.cs
with MIT License
from 71

[SuppressMessage("ReSharper", "PossibleNullReferenceException")]
        public override Expression Visit(Expression node)
        {
            if (_isStopped)
                return node;
            if (_visitedExpressions != null && _visitedExpressions.Contains(node))
                return node;

            if (Pipeline != null)
            {
                Delegate[] projectors = Pipeline.GetInvocationList();

                for (int i = 0; i < projectors.Length; i++)
                {
                    node = (projectors[i] as ExpressionProjector).Invoke(node);

                    if (node == null)
                        return null;
                }
            }

            _visitedExpressions?.Add(node);

            return node.NodeType == ExpressionType.Extension && !node.CanReduce ? node : base.Visit(node);
        }

19 Source : ScopedExpressionVisitor.cs
with MIT License
from 71

public override Expression Visit(Expression node)
        {
            if (node == null)
                return null;

            EnsureCapacity(_depth + 1);
            _scope[_depth++] = node;

            base.Visit(node);

            node = Visit(new ScopedExpression(this, --_depth));

            _scope[_depth] = null;
            return node;
        }

19 Source : DynamicUtils.cs
with MIT License
from akaskela

public override DynamicMetaObject FallbackGetMember(DynamicMetaObject target, DynamicMetaObject errorSuggestion)
        {
            DynamicMetaObject retMetaObject = _innerBinder.Bind(target, new DynamicMetaObject[] { });

            NoThrowExpressionVisitor noThrowVisitor = new NoThrowExpressionVisitor();
            Expression resultExpression = noThrowVisitor.Visit(retMetaObject.Expression);

            DynamicMetaObject finalMetaObject = new DynamicMetaObject(resultExpression, retMetaObject.Restrictions);
            return finalMetaObject;
        }

19 Source : DynamicUtils.cs
with MIT License
from akaskela

public override DynamicMetaObject FallbackSetMember(DynamicMetaObject target, DynamicMetaObject value, DynamicMetaObject errorSuggestion)
        {
            DynamicMetaObject retMetaObject = _innerBinder.Bind(target, new DynamicMetaObject[] { value });

            NoThrowExpressionVisitor noThrowVisitor = new NoThrowExpressionVisitor();
            Expression resultExpression = noThrowVisitor.Visit(retMetaObject.Expression);

            DynamicMetaObject finalMetaObject = new DynamicMetaObject(resultExpression, retMetaObject.Restrictions);
            return finalMetaObject;
        }

19 Source : WeakTypeDelegateGenerator.cs
with MIT License
from albyho

public Delegate Generate(Expression exp)
        {
            _parameters = new List<ParameterExpression>();

            var body = this.Visit(exp);
            var lambda = Expression.Lambda(body, _parameters.ToArray());
            return lambda.Compile();
        }

19 Source : QueryableExtensions.cs
with MIT License
from albyho

public override Expression Visit(Expression exp)
            {
                if (exp == _oldParam)
                {
                    return _replacement;
                }

                return base.Visit(exp);
            }

19 Source : ConstantExtractor.cs
with MIT License
from albyho

public List<object> Extract(Expression exp)
        {
            _constants = new List<object>();
            Visit(exp);
            return _constants;
        }

19 Source : DelegateGenerator.cs
with MIT License
from albyho

public Func<List<object>, object> Generate(Expression exp)
        {
            _parameterCount = 0;
            _parametersExpression =
                Expression.Parameter(typeof(List<object>), "parameters");

            var body = this.Visit(exp); // normalize
            if (body.Type != typeof(object))
            {
                body = Expression.Convert(body, typeof(object));
            }

            var lambda = Expression.Lambda<Func<List<object>, object>>(body, _parametersExpression);
            return lambda.Compile();
        }

19 Source : PartialEvaluatorBase.cs
with MIT License
from albyho

protected override Expression Visit(Expression exp)
        {
            if (exp == null)
            {
                return null;
            }

            if (_candidates.Contains(exp))
            {
                return exp.NodeType == ExpressionType.Constant ? exp :
                    Expression.Constant(_evaluator.Eval(exp), exp.Type);
            }

            return base.Visit(exp);
        }

19 Source : PartialEvaluatorBase.cs
with MIT License
from albyho

protected override Expression Visit(Expression expression)
            {
                if (expression != null)
                {
                    bool saveCannotBeEvaluated = _cannotBeEvaluated;
                    _cannotBeEvaluated = false;

                    base.Visit(expression);

                    if (!_cannotBeEvaluated)
                    {
                        if (_fnCanBeEvaluated(expression))
                        {
                            _candidates.Add(expression);
                        }
                        else
                        {
                            _cannotBeEvaluated = true;
                        }
                    }

                    _cannotBeEvaluated |= saveCannotBeEvaluated;
                }

                return expression;
            }

19 Source : ExpressionHasher.cs
with MIT License
from albyho

protected override Expression Visit(Expression exp)
        {
            if (exp == null) return exp;

            Hash((int)exp.NodeType).Hash(exp.Type);
            return base.Visit(exp);
        }

19 Source : Evaluator.cs
with MIT License
from AlenToma

public override Expression Visit(Expression exp)
            {
                if (exp == null)
                {
                    return null;
                }
                if (this.candidates.Contains(exp))
                {
                    return this.Evaluate(exp);
                }
                return base.Visit(exp);
            }

19 Source : Evaluator.cs
with MIT License
from AlenToma

public override Expression Visit(Expression expression)
            {
                if (expression != null)
                {
                    bool saveCannotBeEvaluated = this.cannotBeEvaluated;
                    this.cannotBeEvaluated = false;
                    base.Visit(expression);
                    if (!this.cannotBeEvaluated)
                    {
                        if (this.fnCanBeEvaluated(expression))
                        {
                            this.candidates.Add(expression);
                        }
                        else
                        {
                            this.cannotBeEvaluated = true;
                        }
                    }
                    this.cannotBeEvaluated |= saveCannotBeEvaluated;
                }
                return expression;
            }

19 Source : LinqToSql.cs
with MIT License
from AlenToma

public override Expression Visit(Expression node)
        {
            var m = base.Visit(node);

            _overridedNodeType = null;
            return m;
        }

19 Source : PredicateBuilder.cs
with MIT License
from alirezanet

public override Expression Visit(Expression node)
         {
            return node == _oldValue ? _newValue : base.Visit(node)!;
         }

19 Source : DdbExpressionVisitor.cs
with MIT License
from AllocZero

protected override Expression VisitMember(MemberExpression node)
        {
            if (node.Expression is ConstantExpression constantExpression && node.Member is FieldInfo fieldInfo)
            {
                var value = fieldInfo.GetValue(constantExpression.Value);
                _builder.Append(value);

                return node;
            }

            if (node.Expression!.NodeType != ExpressionType.Parameter)
                Visit(node.Expression);

            if (_builder.Length > 0)
                _builder.Append('.');

            _builder.Append("#f");
            _builder.Append(_cachedAttributeNames!.Count);

            if (!ClreplacedInfo.PropertiesMap.TryGetValue(node.Member.Name, out var ddbPropertyInfo))
                throw new DdbException(
                    $"Property {node.Member.Name} does not exist in enreplacedy {ClreplacedInfo.Type.Name} or it's not marked by {nameof(DynamoDbPropertyAttribute)} attribute");
            
            _cachedAttributeNames.Add(ddbPropertyInfo.AttributeName);
            ClreplacedInfo = ddbPropertyInfo.RuntimeClreplacedInfo;

            return node;
        }

19 Source : DdbExpressionVisitor.cs
with MIT License
from AllocZero

protected override Expression VisitBinary(BinaryExpression node)
        {
            if (node.NodeType == ExpressionType.ArrayIndex)
            {
                Visit(node.Left);

                _builder.Append('[');
                Visit(node.Right);
                _builder.Append(']');
                
                ClreplacedInfo = ClreplacedInfo.ElementClreplacedInfo!;
            }

            return node;
        }

19 Source : DdbExpressionVisitor.cs
with MIT License
from AllocZero

protected override Expression VisitIndex(IndexExpression node)
        {
            if (node.Object!.NodeType != ExpressionType.Parameter)
                Visit(node.Object);
            
            _builder.Append('[');
            Visit(node.Arguments);
            _builder.Append(']');
            
            ClreplacedInfo = ClreplacedInfo.ElementClreplacedInfo!;
            
            return node;
        }

19 Source : DdbExpressionVisitor.cs
with MIT License
from AllocZero

protected override Expression VisitMethodCall(MethodCallExpression node)
        {
            if (node.Method.IsSpecialName && node.Method.Name == "get_Item")
            {
                Visit(node.Object);
                
                if ((ClreplacedInfo.ClreplacedType & DdbClreplacedType.Dictionary) != 0)
                {
                    _builder.Append('.');
                    Visit(node.Arguments);
                }
                else
                {
                    _builder.Append('[');
                    Visit(node.Arguments);
                    _builder.Append(']'); 
                }

                ClreplacedInfo = ClreplacedInfo.ElementClreplacedInfo!;
            }

            return node;
        }

19 Source : DdbExpressionVisitor.cs
with MIT License
from AllocZero

public void Visit<TEnreplacedy>(Expression expression)
        {
            var enreplacedyType = typeof(TEnreplacedy);
            ClreplacedInfo = _metadata.GetOrAddClreplacedInfo(enreplacedyType);

            _builder.Clear();

            Visit(expression);
        }

19 Source : DdbExpressionVisitor.cs
with MIT License
from AllocZero

public void Visit(DdbClreplacedInfo clreplacedInfo, Expression expression)
        {
            ClreplacedInfo = clreplacedInfo;

            _builder.Clear();

            Visit(expression);
        }

19 Source : ExpressionLogicalOperatorsExtension .cs
with MIT License
from AlphaYu

public override Expression Visit(Expression node)
            {
                if (node == _oldValue)
                    return _newValue;

                return base.Visit(node);
            }

19 Source : ExpressionExtensions.cs
with Apache License 2.0
from AndcultureCode

public override Expression Visit(Expression node)
        {
            return node == _oldValue ? _newValue : base.Visit(node);
        }

19 Source : ExpressionBuilder.cs
with MIT License
from ansel86castro

public static Expression<Func<T, bool>> Combine<T>(Expression<Func<T, bool>> exp1, Expression<Func<T, bool>> exp2, bool or)
        {
            if (exp1 == null && exp2 == null) return null;
            else if (exp1 == null) return exp2;
            else if (exp2 == null) return exp1;

            var body1 = exp1.Body;
            var body2 = exp2.Body;

            var parameter = exp1.Parameters[0];
            Expression exp = or ? Expression.OrElse(exp1, exp2) : Expression.AndAlso(exp1, exp2);

            ParamExpresionVisitor visitor = new ParamExpresionVisitor { ReplaceParameter = parameter };
            exp = visitor.Visit(exp);

            return Expression.Lambda<Func<T, bool>>(exp, parameter);
        }

19 Source : ExpressionBuilder.cs
with MIT License
from ansel86castro

public static Expression<Func<T1, bool>> Combine<T1, T2>(Expression<Func<T1, T2>> targetExp, Expression<Func<T2, bool>> expression)
        {
            ParamExpresionVisitor visitor = new ParamExpresionVisitor { ReplaceParameter = targetExp.Body };
            var exp = visitor.Visit(expression.Body);

            Expression current = targetExp.Body;
            while (current != null && !(current is ParameterExpression))
            {
                current = ((MemberExpression)current).Expression;
            }

            return Expression.Lambda<Func<T1, bool>>(exp, (ParameterExpression)current);
        }

19 Source : ExpressionBuilder.cs
with MIT License
from ansel86castro

public static Expression<Func<T1, object>> Combine<T1, T2>(Expression<Func<T1, T2>> targetExp, Expression<Func<T2, object>> expression)
        {
            ParamExpresionVisitor visitor = new ParamExpresionVisitor { ReplaceParameter = targetExp.Body };
            var exp = visitor.Visit(expression.Body);

            Expression current = targetExp.Body;
            while (current != null && !(current is ParameterExpression))
            {
                current = ((MemberExpression)current).Expression;
            }

            return Expression.Lambda<Func<T1, object>>(exp, (ParameterExpression)current);
        }

19 Source : PartialEvaluator.cs
with MIT License
from anthonyreilly

protected override Expression Visit(Expression exp)
            {
                if (exp == null)
                {
                    return null;
                }
                if (this.candidates.Contains(exp))
                {
                    return this.Evaluate(exp);
                }
                return base.Visit(exp);
            }

19 Source : PartialEvaluator.cs
with MIT License
from anthonyreilly

protected override Expression Visit(Expression expression)
            {
                if (expression != null)
                {
                    var saveCannotBeEvaluated = this.cannotBeEvaluated;
                    this.cannotBeEvaluated = false;
                    base.Visit(expression);
                    if (!this.cannotBeEvaluated)
                    {
                        if (this.fnCanBeEvaluated(expression))
                        {
                            this.candidates.Add(expression);
                        }
                        else
                        {
                            this.cannotBeEvaluated = true;
                        }
                    }
                    this.cannotBeEvaluated |= saveCannotBeEvaluated;
                }
                return expression;
            }

See More Examples