/// <inheritdoc />
        public bool OnNode(object nodeObject, NodeReflection reflection, out object newValue)
        {
            ConfigNode node = string.IsNullOrEmpty(reflection.Name)
                                  ? Node.GetNode(reflection.Id)
                                  : Node.GetNode(reflection.Id, "name", reflection.Name);

            if (node != null)
            {
                var load = new LoadVisitor {
                    Node = node
                };
                int errors = reflection.Load(load, ref nodeObject);

                if (errors > 0)
                {
                    FARLogger.ErrorFormat("{0} errors while loading {1}[{2}]",
                                          errors.ToString(),
                                          node.name,
                                          reflection.Name);
                }
            }

            newValue = nodeObject;
            return(true);
        }
        /// <inheritdoc />
        public bool OnNodeList(ListValueReflection reflection, NodeReflection nodeReflection, out IList newValue)
        {
            ConfigNode[] nodes = Node.GetNodes(reflection.NodeId);
            var          load  = new LoadVisitor();

            int index = 0;
            int i     = 0;

            var items = new List <object>(nodes.Length);

            foreach (ConfigNode node in nodes)
            {
                if (!node.TryGetValue("index", ref i))
                {
                    i = index;
                }
                index++;

                load.Node = node;
                object item = nodeReflection.Load(load, out int errors);
                SetItem(items, item, i);

                if (errors > 0)
                {
                    FARLogger.ErrorFormat("{0} errors while loading {1}[{2}]",
                                          errors.ToString(),
                                          node.name,
                                          i.ToString());
                }
            }

            newValue = items;
            return(true);
        }
        private static void LoadConfigs()
        {
            // clear config cache so it can be rebuilt
            lastConfigs.Clear();

            var load = new LoadVisitor();

            foreach (KeyValuePair <string, ReflectedConfig> pair in ConfigReflection.Instance.Configs)
            {
                ConfigNode[] nodes = GameDatabase.Instance.GetConfigNodes(pair.Key);
                if (pair.Value.Reflection.AllowMultiple)
                {
                    var root = new ConfigNode();
                    foreach (ConfigNode configNode in nodes)
                    {
                        root.AddNode(configNode);
                    }

                    load.Node = root;
                    object instance = pair.Value.Instance;
                    int    errors   = pair.Value.Reflection.Load(load, ref instance);

                    if (errors > 0)
                    {
                        FARLogger.ErrorFormat("{0} errors while loading {1}", errors.ToString(), pair.Key);
                    }
                }
                else
                {
                    if (nodes.Length == 0)
                    {
                        FARLogger.Warning($"Could not find config nodes {pair.Key}");
                        continue;
                    }

                    if (nodes.Length > 1)
                    {
                        FARLogger.Warning($"Found {nodes.Length.ToString()} {pair.Key} nodes");
                    }

                    foreach (ConfigNode node in nodes)
                    {
                        load.Node = node;
                        object instance = pair.Value.Instance;
                        int    errors   = pair.Value.Reflection.Load(load, ref instance);

                        if (errors > 0)
                        {
                            FARLogger.ErrorFormat("{0} errors while loading {1}", errors.ToString(), node.name);
                        }
                    }
                }
            }

            using LoadGuard guard = Guard(Operation.Saving);
            SaveConfigs("Custom", true, ".cfg.far", FARConfig.Debug.DumpOnLoad);
        }