コード例 #1
0
        /// <summary>
        /// Visits a new expression slim tree node, produces a new expression.
        /// </summary>
        /// <param name="node">Node to visit.</param>
        /// <param name="arguments">Argument expressions.</param>
        /// <returns>The new expression represented by the expression slim node.</returns>
        protected override Expression MakeNew(NewExpressionSlim node, ReadOnlyCollection <Expression> arguments)
        {
            if (node.Constructor != null)
            {
                var constructor = MakeConstructor(node.Constructor);

                var slimMembers = node.Members;

                if (slimMembers != null)
                {
                    var count   = slimMembers.Count;
                    var members = new MemberInfo[count];
                    for (var i = 0; i < count; i++)
                    {
                        members[i] = MakeMember(slimMembers[i]);
                    }

                    return(_factory.New(constructor, arguments, members));
                }
                else
                {
                    return(_factory.New(constructor, arguments));
                }
            }
            else
            {
                var type = MakeType(node.Type);
                return(_factory.New(type));
            }
        }
コード例 #2
0
        /// <summary>
        /// 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.
        /// </summary>
        /// <param name="newExpression">The <see cref="NewExpression"/> child node of the result.</param>
        /// <param name="bindings">The <see cref="Bindings"/> child node of the result.</param>
        /// <returns>This expression if no children are changed or an expression with the updated children.</returns>
        public MemberInitExpressionSlim Update(NewExpressionSlim newExpression, ReadOnlyCollection <MemberBindingSlim> bindings)
        {
            if (newExpression == NewExpression && bindings == Bindings)
            {
                return(this);
            }

            return(new MemberInitExpressionSlim(newExpression, bindings));
        }
コード例 #3
0
        /// <summary>
        /// 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.
        /// </summary>
        /// <param name="newExpression">The <see cref="NewExpression"/> child node of the result.</param>
        /// <param name="initializers">The <see cref="Initializers"/> child node of the result.</param>
        /// <returns>This expression if no children are changed or an expression with the updated children.</returns>
        public ListInitExpressionSlim Update(NewExpressionSlim newExpression, ReadOnlyCollection <ElementInitSlim> initializers)
        {
            if (newExpression == NewExpression && initializers == Initializers)
            {
                return(this);
            }

            return(new ListInitExpressionSlim(newExpression, initializers));
        }
コード例 #4
0
#pragma warning disable IDE0079 // Remove unnecessary suppression.
#pragma warning disable CA1711  // Replace New suffix. (Name of expression tree node.)

        /// <summary>
        /// Visits an object creation expression tree node.
        /// </summary>
        /// <param name="node">Node to visit.</param>
        /// <returns>Result of visiting the node.</returns>
        protected internal virtual ExpressionSlim VisitNew(NewExpressionSlim node)
        {
            var arguments = VisitArguments(node);

            if (arguments != null)
            {
                return(node.Rewrite(arguments));
            }

            return(node);
        }
コード例 #5
0
        protected internal override ExpressionSlim VisitNew(NewExpressionSlim node)
        {
            // CONSIDER: This doesn't print the Members collection if present. We can consider adding this in the future.

            Append("New(");
            if (node.Constructor != null)
            {
                Append(node.Constructor);
                if (node.ArgumentCount > 0)
                {
                    Append(", ");
                    Visit(", ", node);
                }
            }
            else
            {
                Append(node.Type);
            }
            Append(')');

            return(node);
        }
コード例 #6
0
 internal MemberInitExpressionSlim(NewExpressionSlim newExpression, ReadOnlyCollection <MemberBindingSlim> bindings)
 {
     NewExpression = newExpression;
     Bindings      = bindings;
 }
コード例 #7
0
 internal ListInitExpressionSlim(NewExpressionSlim newExpression, ReadOnlyCollection <ElementInitSlim> initializers)
 {
     NewExpression = newExpression;
     Initializers  = initializers;
 }