Update() публичный Метод

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.
Результат TryExpression
        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;
        }
Пример #2
0
 /// <summary>
 /// Visits the children of the <see cref="TryExpression"/>.
 /// </summary>
 /// <param name="node">The expression to visit.</param>
 /// <returns>The modified expression, if it or any subexpression was modified;
 /// otherwise, returns the original expression.</returns>
 protected internal virtual Expression VisitTry(TryExpression node)
 {
     return(node.Update(
                Visit(node.Body),
                Visit(node.Handlers, VisitCatchBlock),
                Visit(node.Finally),
                Visit(node.Fault)
                ));
 }
        /// <summary>
        /// Updates the specified try expression using the specified handlers, finally, and fault blocks.
        /// This method protects against invalid updates of try expressions and can return the body of the
        /// original try expression if no handlers or finally or fault blocks remain.
        /// </summary>
        /// <param name="node">The node to update.</param>
        /// <param name="body">The new body.</param>
        /// <param name="handlers">The new catch handlers.</param>
        /// <param name="finally">The new finally block.</param>
        /// <param name="fault">The new fault block.</param>
        /// <returns>The updated expression or the original expression if nothing changed.</returns>
        private Expression Update(TryExpression node, Expression body, IList <CatchBlock> handlers, Expression @finally, Expression fault)
        {
            if ((handlers == null || handlers.Count == 0) && @finally == null && fault == null)
            {
                return(ChangeType(body, node.Type));
            }

            return(node.Update(body, handlers, @finally, fault));
        }
Пример #4
0
        /// <summary>
        ///     Visits the children of the <see cref="TryExpression" />.
        /// </summary>
        /// <param name="node">The expression to visit.</param>
        /// <returns>
        ///     The modified expression, if it or any subexpression was modified;
        ///     otherwise, returns the original expression.
        /// </returns>
        protected internal virtual Expression VisitTry(TryExpression node)
        {
            if (node == null)
            {
                throw new ArgumentNullException(nameof(node));
            }

            return(node.Update
                   (
                       Visit(node.Body),
                       Visit(node.Handlers, VisitCatchBlock),
                       Visit(node.Finally),
                       Visit(node.Fault)
                   ));
        }
 protected internal virtual Expression VisitTry(TryExpression node)
 {
     return(node.Update(this.Visit(node.Body), Visit <CatchBlock>(node.Handlers, new Func <CatchBlock, CatchBlock>(this.VisitCatchBlock)), this.Visit(node.Finally), this.Visit(node.Fault)));
 }