Exemplo n.º 1
0
        private void IterateElements(Scope getter, bool iterateVariables, bool iterateMethods, Func <ScopeIterate, ScopeIterateAction> element)
        {
            Scope current = this;

            bool getPrivate   = true;
            bool getProtected = true;

            while (current != null)
            {
                List <IScopeable> checkScopeables = new List <IScopeable>();
                if (iterateVariables)
                {
                    checkScopeables.AddRange(current.Variables);
                }
                if (iterateMethods)
                {
                    checkScopeables.AddRange(current.Methods);
                }

                bool stopAfterScope = false;

                foreach (IScopeable check in checkScopeables)
                {
                    // Check if the accessor is valid.
                    bool accessorMatches = check.AccessLevel == AccessLevel.Public ||
                                           (getPrivate && check.AccessLevel == AccessLevel.Private) ||
                                           (getProtected && check.AccessLevel == AccessLevel.Protected);

                    ScopeIterateAction action = element(new ScopeIterate(current, check, accessorMatches));
                    if (action == ScopeIterateAction.Stop)
                    {
                        return;
                    }
                    if (action == ScopeIterateAction.StopAfterScope)
                    {
                        stopAfterScope = true;
                    }
                }

                if (current.PrivateCatch)
                {
                    getPrivate = false;
                }
                if (current.ProtectedCatch)
                {
                    getProtected = false;
                }
                if (stopAfterScope)
                {
                    return;
                }

                current = current.Parent;
            }
        }
        private void IterateElements(bool iterateVariables, bool iterateMethods, Func <ScopeIterate, ScopeIterateAction> element, Func <Scope, ScopeIterateAction> onEmpty = null)
        {
            Scope current = this;

            bool getPrivate   = true;
            bool getProtected = true;

            while (current != null)
            {
                List <IScopeable> checkScopeables = new List <IScopeable>();

                // If variables are being iterated, add them to the list.
                if (iterateVariables)
                {
                    checkScopeables.AddRange(current._variables);
                }

                // If functions are being iterated, add them to the list.
                if (iterateMethods)
                {
                    foreach (var group in current._methodGroups)
                    {
                        checkScopeables.AddRange(group.Functions);
                    }
                }

                bool stopAfterScope = false;

                foreach (IScopeable check in checkScopeables)
                {
                    // Check if the accessor is valid.
                    bool accessorMatches = check.AccessLevel == AccessLevel.Public ||
                                           (getPrivate && check.AccessLevel == AccessLevel.Private) ||
                                           (getProtected && check.AccessLevel == AccessLevel.Protected);

                    ScopeIterateAction action = element(new ScopeIterate(current, check, accessorMatches));
                    if (action == ScopeIterateAction.Stop)
                    {
                        return;
                    }
                    if (action == ScopeIterateAction.StopAfterScope)
                    {
                        stopAfterScope = true;
                    }
                }
                // If there are no scopeables and onEmpty is not null, invoke onEmpty.
                if (checkScopeables.Count == 0 && onEmpty != null)
                {
                    ScopeIterateAction action = onEmpty.Invoke(current);
                    if (action != ScopeIterateAction.Continue)
                    {
                        return;
                    }
                }

                if (current.PrivateCatch)
                {
                    getPrivate = false;
                }
                if (current.ProtectedCatch)
                {
                    getProtected = false;
                }
                if (stopAfterScope)
                {
                    return;
                }

                current = current.Parent;
            }
        }