Esempio n. 1
0
        public override object Evaluate(Context context)
        {
            Log.WriteLine("Refactor Evaluate", "{0}: Let", Line);

            for (int i = 0; i < m_locals.Length; ++i)
            {
                object value = m_values[i].Evaluate(context);
                context.AddLocal(m_locals[i], value);
            }

            object result = null;
            foreach (Statement statement in m_block)
            {
                result = statement.Evaluate(context);
            }

            for (int i = 0; i < m_locals.Length; ++i)
            {
                context.RemoveLocal(m_locals[i]);
            }

            return result;
        }
Esempio n. 2
0
        public override object Evaluate(Context context)
        {
            Log.WriteLine("Refactor Evaluate", "{0}: For", Line);

            object result = m_elements.Evaluate(context);

            object[] elements = (object[]) result;
            if (elements == null && result != null)
                throw new EvaluateException(m_elements.Line, "For statement should return a Sequence, but was a {0}.", RefactorType.GetName(result.GetType()));

            result = null;
            if (elements != null)
            {
                foreach (object element in elements)
                {
                    context.AddLocal(m_local, element);

                    if (DoIsValidElement(context))
                    {
                        foreach (Statement statement in m_block)
                        {
                            result = statement.Evaluate(context);
                        }
                    }

                    context.RemoveLocal(m_local);
                }
            }

            return result;
        }