Ejemplo n.º 1
0
        private void Initialize(ElementInit elementInit)
        {
            if (elementInit == null) throw new ArgumentNullException("elementInit");

            AddMethod = new MethodInfoNode(Context, elementInit.AddMethod);
            Arguments = new ExpressionNodeList(Context, elementInit.Arguments);
        }
Ejemplo n.º 2
0
 public static ElementInit Serialize(E.ElementInit elementInit)
 {
     return(new ElementInit()
     {
         AddMethod = MethodRef.Serialize(elementInit.AddMethod),
         Arguments = elementInit.Arguments.Select(Node.Serialize).ToArray(),
     });
 }
Ejemplo n.º 3
0
        protected override ElementInit VisitElementInit(ElementInit node)
        {
            var args = Visit(node.Arguments);
            foreach(var arg in args)
                AddParameter(arg);

            return null;
        }
Ejemplo n.º 4
0
 void ElementInit(ElementInit elementInit)
 {
     indent++;
     Write("Arguments:");
     foreach (var argument in elementInit.Arguments) {
         Expression(argument);
     }
     indent--;
 }
Ejemplo n.º 5
0
 public EditableElementInit(ElementInit elmInit)
     : this()
 {
     AddMethod = elmInit.AddMethod;
     foreach (Expression ex in elmInit.Arguments)
     {
         Arguments.Add(EditableExpression.Create(ex));
     }
 }
        private ElementInit[] GetInitializers(MethodInfo invoke, out ParameterExpression[] parameters)
        {
            ParameterInfo[] parameterInfos = invoke.GetParameters();
            var initializers = new ElementInit[parameterInfos.Length];
            parameters = new ParameterExpression[parameterInfos.Length];
            for (var i = 0; i < parameterInfos.Length; i++)
            {
                Expression dictionaryValue;
                Expression dictionaryKey;
                ParameterExpression parameter;

                BuildInitializer(out dictionaryValue, out dictionaryKey, out parameter, parameterInfos[i]);
                parameters[i] = parameter;
                initializers[i] = Expression.ElementInit(Tokens.DictionaryAdd, new[] { dictionaryKey, dictionaryValue });
            }
            return initializers;
        }
 protected virtual void PVisitElementInitializer(ElementInit initializer)
 {
 }
Ejemplo n.º 8
0
 private ElementInit Convert(LinqExp.ElementInit linqElementInit)
 {
     return(Expression.ElementInit(
                linqElementInit.AddMethod,
                Convert(linqElementInit.Arguments)));
 }
Ejemplo n.º 9
0
 protected virtual void VisitElementInitializer(ElementInit initializer)
 {
     VisitExpressionList(initializer.Arguments);
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Visits the children of the <see cref="ElementInit"/>.
 /// </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 virtual ElementInit VisitElementInit(ElementInit node)
 {
     return(node.Update(Visit(node.Arguments)));
 }
Ejemplo n.º 11
0
        //protected internal virtual Expression VisitDebugInfo(DebugInfoExpression node)
        //{
        //    return (Expression)null;
        //}

        //protected internal virtual Expression VisitDefault(DefaultExpression node)
        //{
        //    return (Expression)null;
        //}

        //protected internal virtual Expression VisitDynamic(DynamicExpression node)
        //{
        //    return (Expression)null;
        //}

        protected virtual ElementInit VisitElementInit(ElementInit node)
        {
            return((ElementInit)null);
        }
Ejemplo n.º 12
0
        protected virtual ElementInit VisitElementInitializer(ElementInit initializer)
        {
            var arguments = VisitExpressionList(initializer.Arguments);

            return(arguments != initializer.Arguments ? Expression.ElementInit(initializer.AddMethod, arguments) : initializer);
        }
Ejemplo n.º 13
0
 /// <summary>
 /// Gets the debug view for the specified element initializer.
 /// </summary>
 /// <param name="initializer">The element initializer to get a debug view for.</param>
 /// <returns>Debug view for the specified element initializer.</returns>
 public XNode GetDebugView(ElementInit initializer)
 {
     return(Visit(initializer));
 }
Ejemplo n.º 14
0
 protected override ElementInit VisitElementInitializer(ElementInit initializer) => InvokeEvent(ElementInitializerVisited, initializer, base.VisitElementInitializer);
 protected override ElementInitExpressionTree MakeElementInit(ElementInit node, ReadOnlyCollection <ExpressionTree> arguments) => new(node, arguments);
Ejemplo n.º 16
0
 protected virtual void VisitElementInitializer(ElementInit initializer)
 {
     this.VisitExpressionList(initializer.Arguments);
     throw new NotImplementedException ();
 }
            private new RemoteLinq.ElementInit VisitElementInitializer(SystemLinq.ElementInit initializer)
            {
                var arguments = VisitExpressionList(initializer.Arguments).Select(Unwrap);

                return(new RemoteLinq.ElementInit(_typeInfoProvider.GetMethodInfo(initializer.AddMethod), arguments));
            }
Ejemplo n.º 18
0
 public EditableElementInit(ElementInit elementInit)
 {
     AddMethod = elementInit.AddMethod;
     arguments = new EditableExpressionCollection<Expression>(elementInit.Arguments);
 }
Ejemplo n.º 19
0
        /// <summary>
        /// Creates a <see cref="ListInitExpression"/> that uses a specified method to add elements to a collection. 
        /// </summary>
        /// <param name="newExpression">A <see cref="NewExpression"/> to set the <see cref="P:ListInitExpression.NewExpression"/> property equal to.</param>
        /// <param name="addMethod">A <see cref="MethodInfo"/> that represents an instance method named "Add" (case insensitive), that adds an element to a collection. </param>
        /// <param name="initializers">An <see cref="IEnumerable{T}"/> that contains <see cref="Expression"/> objects to use to populate the Initializers collection.</param>
        /// <returns>A <see cref="ListInitExpression"/> that has the <see cref="P:ListInitExpression.NodeType"/> property equal to ListInit and the <see cref="P:ListInitExpression.NewExpression"/> property set to the specified value.</returns>
        public static ListInitExpression ListInit(NewExpression newExpression, MethodInfo addMethod, IEnumerable<Expression> initializers)
        {
            if (addMethod == null)
            {
                return ListInit(newExpression, initializers);
            }
            ContractUtils.RequiresNotNull(newExpression, "newExpression");
            ContractUtils.RequiresNotNull(initializers, "initializers");

            var initializerlist = initializers.ToReadOnly();
            if (initializerlist.Count == 0)
            {
                throw Error.ListInitializerWithZeroMembers();
            }
            ElementInit[] initList = new ElementInit[initializerlist.Count];
            for (int i = 0; i < initializerlist.Count; i++)
            {
                initList[i] = ElementInit(addMethod, initializerlist[i]);
            }
            return ListInit(newExpression, new TrueReadOnlyCollection<ElementInit>(initList));
        }
Ejemplo n.º 20
0
		protected override void VisitElementInitializer (ElementInit initializer)
		{
			object target = null;
			if (!initializer.AddMethod.IsStatic)
				target = Pop ();

			var arguments = VisitListExpressions (initializer.Arguments);
			InvokeMethod (initializer.AddMethod, target, arguments);

			if (!initializer.AddMethod.IsStatic)
				Push (target);
		}
Ejemplo n.º 21
0
 /// <summary>
 /// Constructor with an <see cref="ElementInit"/> and an <see cref="ExpressionConverter"/>.
 /// </summary>
 /// <param name="elementInit">The original, not serializable <see cref="ElementInit"/>.</param>
 /// <param name="expConverter">The <see cref="ExpressionConverter"/> to convert contained <see cref="Expression">Expressions</see>.</param>
 public SerializableElementInit(ElementInit elementInit, ExpressionConverter expConverter)
 {
     Arguments = elementInit.Arguments.MakeSerializableCollection<SerializableExpression>(expConverter);
     AddMethod = elementInit.AddMethod;
 }
Ejemplo n.º 22
0
 protected override ElementInit VisitElementInitializer(ElementInit initializer)
 {
     if (initializer.Arguments.Count > 1)
     {
         this.Write("{");
         for (int i = 0, n = initializer.Arguments.Count; i < n; i++)
         {
             this.Visit(initializer.Arguments[i]);
             if (i < n - 1)
             {
                 this.Write(", ");
             }
         }
         this.Write("}");
     }
     else
     {
         this.Visit(initializer.Arguments[0]);
     }
     return initializer;
 }
Ejemplo n.º 23
0
 protected virtual ElementInit VisitElementInitializer(ElementInit initializer)
 {
     var arguments = VisitExpressionList(initializer.Arguments);
     return arguments != initializer.Arguments ? Expression.ElementInit(initializer.AddMethod, arguments) : initializer;
 }
        /// <summary>
        /// Creates a <see cref="ListInitExpression"/> that uses a specified method to add elements to a collection. 
        /// </summary>
        /// <param name="newExpression">A <see cref="NewExpression"/> to set the <see cref="ListInitExpression.NewExpression"/> property equal to.</param>
        /// <param name="addMethod">A <see cref="MethodInfo"/> that represents an instance method named "Add" (case insensitive), that adds an element to a collection.</param>
        /// <param name="initializers">An <see cref="IEnumerable{T}"/> that contains <see cref="Expression"/> objects to use to populate the Initializers collection.</param>
        /// <returns>A <see cref="ListInitExpression"/> that has the <see cref="NodeType"/> property equal to <see cref="ExpressionType.ListInit"/> and the <see cref="ListInitExpression.NewExpression"/> property set to the specified value.</returns>
        public static ListInitExpression ListInit(NewExpression newExpression, MethodInfo addMethod, IEnumerable<Expression> initializers)
        {
            if (addMethod == null)
            {
                return ListInit(newExpression, initializers);
            }
            ContractUtils.RequiresNotNull(newExpression, nameof(newExpression));
            ContractUtils.RequiresNotNull(initializers, nameof(initializers));

            ReadOnlyCollection<Expression> initializerlist = initializers.ToReadOnly();
            ElementInit[] initList = new ElementInit[initializerlist.Count];
            for (int i = 0; i < initializerlist.Count; i++)
            {
                initList[i] = ElementInit(addMethod, initializerlist[i]);
            }
            return ListInit(newExpression, new TrueReadOnlyCollection<ElementInit>(initList));
        }
Ejemplo n.º 25
0
 protected virtual bool CompareElementInit(ElementInit a, ElementInit b)
 {
     return a.AddMethod == b.AddMethod
         && this.CompareExpressionList(a.Arguments, b.Arguments);
 }
 protected virtual ElementInit VisitElementInitializer(ElementInit initializer, Stack<string> stack, Stack<IElasticPropertyAttribute> properties)
 {
     ReadOnlyCollection<Expression> arguments = this.VisitExpressionList(initializer.Arguments, stack, properties);
     if (arguments != initializer.Arguments)
     {
         return Expression.ElementInit(initializer.AddMethod, arguments);
     }
     return initializer;
 }
Ejemplo n.º 27
0
 /// <summary>
 /// Visits an ElementInit.
 /// </summary>
 /// <param name="node">The ElementInit.</param>
 /// <returns>The ElementInit (possibly modified).</returns>
 protected virtual ElementInit VisitElementInit(ElementInit node)
 {
     ReadOnlyCollection<Expression> arguments = VisitExpressionList(node.Arguments);
     if (arguments != node.Arguments)
     {
         return Expression.ElementInit(node.AddMethod, arguments);
     }
     return node;
 }
 public ElementInitExpressionTree Visit(ElementInit node) => base.VisitElementInit(node);
    public virtual bool IsEvaluatableElementInit (ElementInit node)
    {
      ArgumentUtility.CheckNotNull ("node", node);

      return true;
    }
 internal virtual ElementInit VisitElementInitializer(ElementInit initializer)
 {
     var arguments = VisitExpressionList(initializer.Arguments);
     if (arguments != initializer.Arguments)
     {
         return Expression.ElementInit(initializer.AddMethod, arguments);
     }
     return initializer;
 }
 /// <summary>
 /// Visits an ElementInit node.
 /// </summary>
 /// <param name="node">The ElementInit node.</param>
 /// <returns>The ElementInit node.</returns>
 protected override ElementInit VisitElementInit(ElementInit node)
 {
     _sb.Append("<ElementInit>");
     return node;
 }
        protected override ElementInit VisitElementInitializer(ElementInit expression)
        {
            ElementInit current;
            if (!TryGetCurrent(expression, out current))
            {
                return expression;
            }

            if (!(this.result &= current.AddMethod == expression.AddMethod))
            {
                return expression;
            }

            this.currentObject = current.Arguments;
            this.VisitExpressionList(expression.Arguments);
            if (!this.result)
            {
                return expression;
            }

            this.currentObject = current;
            return expression;
        }
 /// <summary>
 /// ElementInit visit method
 /// </summary>
 /// <param name="initializer">The ElementInit expression to visit</param>
 /// <returns>The visited ElementInit expression </returns>
 internal override ElementInit VisitElementInitializer(ElementInit initializer)
 {
     this.VisitExpressionList(initializer.Arguments);
     return initializer;
 }
Ejemplo n.º 34
0
        /// <summary>
        /// Visits the children of the <c>ElementInit</c>.
        /// </summary>
        /// <param name="initializer">The expression to visit.</param>
        /// <returns>The modified expression, if it or any subexpression was modified; 
        /// otherwise, returns the original expression.</returns>
        protected virtual ElementInit VisitElementInitializer(ElementInit initializer)
        {
            if (initializer == null)
                throw new ArgumentNullException("initializer");

            var arguments = VisitExpressionList(initializer.Arguments);
            return arguments == initializer.Arguments ? initializer : Expression.ElementInit(initializer.AddMethod, arguments);
        }
Ejemplo n.º 35
0
		protected virtual ElementInit VisitElementInitializer (ElementInit initializer)
		{
			Expression[] args;
			if (VisitExpressionList (initializer.Arguments, out args))
				return Expression.ElementInit (initializer.AddMethod, args);

			return initializer;
		}
Ejemplo n.º 36
0
 public ElementInitNode(INodeFactory factory, ElementInit elementInit)
     : base(factory)
 {
     this.Initialize(elementInit);
 }
Ejemplo n.º 37
0
        /// <summary>
        /// Creates a <see cref="ListInitExpression"/> that uses a specified method to add elements to a collection.
        /// </summary>
        /// <param name="newExpression">A <see cref="NewExpression"/> to set the <see cref="P:ListInitExpression.NewExpression"/> property equal to.</param>
        /// <param name="addMethod">A <see cref="MethodInfo"/> that represents an instance method named "Add" (case insensitive), that adds an element to a collection. </param>
        /// <param name="initializers">An <see cref="IEnumerable{T}"/> that contains <see cref="Expression"/> objects to use to populate the Initializers collection.</param>
        /// <returns>A <see cref="ListInitExpression"/> that has the <see cref="P:ListInitExpression.NodeType"/> property equal to ListInit and the <see cref="P:ListInitExpression.NewExpression"/> property set to the specified value.</returns>
        public static ListInitExpression ListInit(NewExpression newExpression, MethodInfo addMethod, IEnumerable <Expression> initializers)
        {
            if (addMethod == null)
            {
                return(ListInit(newExpression, initializers));
            }
            ContractUtils.RequiresNotNull(newExpression, "newExpression");
            ContractUtils.RequiresNotNull(initializers, "initializers");

            List <ElementInit> initList = null;

            ElementInit[] initArray = null;

            initializers = initializers.NullOrEmptyChecked
                           (
                () =>
            {
                throw Error.ListInitializerWithZeroMembers();
            },
                () => initList     = new List <ElementInit>(),
                count => initArray = new ElementInit[count]
                           );
            var enumerator = initializers.GetEnumerator();

            try
            {
                enumerator.MoveNext();
                var initializer = enumerator.Current;
                if (addMethod == null)
                {
                    return(ListInit(newExpression, initializers));
                }
                if (initList != null)
                {
                    initList.Add(ElementInit(addMethod, initializer));
                    while (enumerator.MoveNext())
                    {
                        initializer = enumerator.Current;
                        initList.Add(ElementInit(addMethod, initializer));
                    }
                    initArray = initList.ToArray();
                }
                else
                {
                    var index = 0;
                    initArray[index] = ElementInit(addMethod, initializer);
                    index++;
                    while (enumerator.MoveNext())
                    {
                        initializer      = enumerator.Current;
                        initArray[index] = ElementInit(addMethod, initializer);
                        index++;
                    }
                }
            }
            finally
            {
                enumerator.Dispose();
            }
            ValidateListInitArgs(newExpression.Type, initArray);
            return(new ListInitExpression(newExpression, initArray));
        }
 /// <summary>
 /// Visits an ElementInit.
 /// </summary>
 /// <param name="initializer">The ElementInit.</param>
 /// <returns>The ElementInit (possibly modified).</returns>
 protected virtual ElementInit VisitElementInitializer(ElementInit initializer)
 {
     ReadOnlyCollection<Expression> arguments = this.VisitExpressionList(initializer.Arguments);
     if (arguments != initializer.Arguments)
     {
         return Expression.ElementInit(initializer.AddMethod, arguments);
     }
     return initializer;
 }
 /// <summary>
 /// Visit a element initialized expression.
 /// </summary>
 /// <param name="elementInitExp"></param>
 /// <returns></returns>
 protected virtual ElementInit VisitElementInitializer(ElementInit elementInitExp)
 {
     ReadOnlyCollection<Expression> arguments = VisitList(elementInitExp.Arguments);
     if (arguments != elementInitExp.Arguments)
     {
         return Expression.ElementInit(elementInitExp.AddMethod, arguments);
     }
     return elementInitExp;
 }
 /// <summary>
 /// ElementInit visit method
 /// </summary>
 /// <param name="initializer">The ElementInit expression to visit</param>
 /// <returns>The visited ElementInit expression </returns>
 internal override ElementInit VisitElementInitializer(ElementInit initializer)
 {
     throw new NotImplementedException();
 }
 /// <summary>
 /// Visits an ElementInit node.
 /// </summary>
 /// <param name="node">The ElementInit node.</param>
 /// <returns>The ElementInit node.</returns>
 protected override ElementInit VisitElementInit(ElementInit node)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 42
-1
 private static ElementInit VisitElementInit(ElementInit node)
 {
     throw new NotImplementedException();
 }