Пример #1
0
        private bool Equals(ItemListExpression other)
        {
            if (_arguments.Length != other._arguments.Length)
            {
                return(false);
            }

            for (int i = 0; i < _arguments.Length; ++i)
            {
                if (!Equals(_arguments[i], other._arguments[i]))
                {
                    return(false);
                }
            }

            return(true);
        }
Пример #2
0
        private static bool OptimizeItemList(ItemListExpression expression, out IExpression optimized)
        {
            optimized = null;

            var  arguments         = new List <IExpression>();
            bool optimizedAnything = false;

            foreach (IExpression argument in expression.Arguments)
            {
                IExpression optimizedItem = Run(argument);
                if (!ReferenceEquals(optimizedItem, argument))
                {
                    optimizedAnything = true;
                }

                var childList = optimizedItem as ItemListExpression;
                if (childList != null)
                {
                    arguments.AddRange(childList.Arguments);
                    optimizedAnything = true;
                }
                else
                {
                    arguments.Add(optimizedItem);
                }
            }

            if (arguments.Count == 1)
            {
                optimized = arguments[0];
                return(true);
            }

            if (!optimizedAnything)
            {
                return(false);
            }

            optimized = new ItemListExpression(arguments);
            return(true);
        }