IronRuby.Builtins.RubyModule.EnumerateConstants C# (CSharp) Метод

EnumerateConstants() публичный Метод

public EnumerateConstants ( Func action ) : bool
action Func
Результат bool
        public bool EnumerateConstants(Func<RubyModule, string, object, bool>/*!*/ action) {
            Context.RequiresClassHierarchyLock();

            InitializeConstantsNoLock();

            foreach (var constant in _constants) {
                var name = constant.Key;
                var storage = constant.Value;
                if (!storage.IsRemoved && action(this, name, storage.Value)) {
                    return true;
                }
            }

            if (_namespaceTracker != null) {
                foreach (KeyValuePair<string, object> constant in _namespaceTracker) {
                    string name = constant.Key;
                    // we check if we haven't already yielded the value so that we don't yield values hidden by a user defined constant:
                    if (!_constants.ContainsKey(name) && action(this, name, constant.Value)) {
                        return true;
                    }
                }
            }

            return false;
        }

Usage Example

Пример #1
0
        public static object EachObject(BlockParam block, RubyModule /*!*/ self, [NotNull] RubyClass /*!*/ theClass)
        {
            if (!theClass.HasAncestor(self.Context.ModuleClass))
            {
                throw RubyExceptions.CreateRuntimeError("each_object only supported for objects of type Class or Module");
            }

            if (block == null)
            {
                throw RubyExceptions.NoBlockGiven();
            }

            int matches = 0;
            List <RubyModule>  visitedModules = new List <RubyModule>();
            Stack <RubyModule> pendingModules = new Stack <RubyModule>();

            pendingModules.Push(theClass.Context.ObjectClass);

            while (pendingModules.Count > 0)
            {
                RubyModule next = pendingModules.Pop();
                visitedModules.Add(next);

                if (theClass.Context.IsKindOf(next, theClass))
                {
                    matches++;

                    object result;
                    if (block.Yield(next, out result))
                    {
                        return(result);
                    }
                }

                using (theClass.Context.ClassHierarchyLocker()) {
                    next.EnumerateConstants(delegate(RubyModule module, string name, object value) {
                        RubyModule constAsModule = value as RubyModule;
                        if (constAsModule != null && !visitedModules.Contains(constAsModule))
                        {
                            pendingModules.Push(constAsModule);
                        }
                        return(false);
                    });
                }
            }
            return(matches);
        }
All Usage Examples Of IronRuby.Builtins.RubyModule::EnumerateConstants
RubyModule