System.Linq.Expressions.TryExpression.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 ( Expression body, IEnumerable handlers, Expression @finally, Expression fault ) : TryExpression
body Expression The property of the result.
handlers IEnumerable The property of the result.
@finally Expression
fault Expression The property of the result.
return TryExpression
        public TryExpression Update(Expression body, IEnumerable<CatchBlock> handlers, Expression @finally, Expression fault)
        {
            if (body == Body && handlers == Handlers && @finally == Finally && fault == Fault)
            {
                return this;
            }
            return Expression.MakeTry(Type, body, @finally, fault, handlers);
        }
    }

Usage Example

        protected override Expression VisitTry(TryExpression node)
        {
            var res = default(Expression);

            if (node.Finally != null || node.Fault != null)
            {
                var body = Visit(node.Body);
                var handlers = Visit(node.Handlers, VisitCatchBlock);

                if (node.Finally != null)
                {
                    Debug.Assert(node.Fault == null);

                    var @finally = default(Expression);

                    if (VisitAndFindAwait(node.Finally, out @finally))
                    {
                        if (handlers.Count != 0)
                        {
                            body = Expression.TryCatch(body, handlers.ToArray());
                        }

                        res = RewriteHandler(body, @finally, isFault: false);
                    }
                    else
                    {
                        res = node.Update(body, handlers, @finally, null);
                    }
                }
                else
                {
                    Debug.Assert(node.Finally == null);

                    var fault = default(Expression);

                    if (VisitAndFindAwait(node.Fault, out fault))
                    {
                        Debug.Assert(handlers.Count == 0);

                        res = RewriteHandler(body, fault, isFault: true);
                    }
                    else
                    {
                        res = node.Update(body, handlers, null, fault);
                    }
                }
            }
            else
            {
                res = base.VisitTry(node);
            }

            return res;
        }
All Usage Examples Of System.Linq.Expressions.TryExpression::Update