System.Linq.Expressions.NewExpression.Update C# (CSharp) Method

Update() public method

Creates a new expression that is like this one, but using the supplied children. If all of the children are the same, it will return this expression.
public Update ( IEnumerable arguments ) : NewExpression
arguments IEnumerable The property of the result.
return NewExpression
        public NewExpression Update(IEnumerable<Expression> arguments)
        {
            if (arguments == Arguments)
            {
                return this;
            }
            if (Members != null)
            {
                return Expression.New(Constructor, arguments, Members);
            }
            return Expression.New(Constructor, arguments);
        }
    }

Usage Example

        //make projections of enums work
        protected override Expression VisitNew(NewExpression node)
        {
            IEnumerable<Expression> arguments = node.Arguments
                .Select((arg, i) =>
                            {
                                Expression newarg = Visit(arg);
                                if (arg.Type.IsEnum && newarg.Type == typeof (Int32))
                                    return Expression.Convert(newarg, arg.Type);
                                    //force an in mem convert from int to enum
                                else
                                    return newarg;
                            });

            return node.Update(arguments);
        }
All Usage Examples Of System.Linq.Expressions.NewExpression::Update