Contains() public méthode

public Contains ( string key ) : bool
key string
Résultat bool
Exemple #1
0
        public Settings(string file, Arguments args)
        {
            settingsFile = file;
            Sections     = new Dictionary <string, object>()
            {
                { "Player", Player },
                { "Game", Game },
                { "Sound", Sound },
                { "Graphics", Graphics },
                { "Server", Server },
                { "Debug", Debug },
                { "Keys", Keys },
                { "Chat", Chat }
            };

            // Override fieldloader to ignore invalid entries
            var err1 = FieldLoader.UnknownFieldAction;
            var err2 = FieldLoader.InvalidValueAction;

            try
            {
                FieldLoader.UnknownFieldAction = (s, f) => Console.WriteLine("Ignoring unknown field `{0}` on `{1}`".F(s, f.Name));

                if (File.Exists(settingsFile))
                {
                    var yaml = MiniYaml.DictFromFile(settingsFile);

                    foreach (var kv in Sections)
                    {
                        if (yaml.ContainsKey(kv.Key))
                        {
                            LoadSectionYaml(yaml[kv.Key], kv.Value);
                        }
                    }
                }

                // Override with commandline args
                foreach (var kv in Sections)
                {
                    foreach (var f in kv.Value.GetType().GetFields())
                    {
                        if (args.Contains(kv.Key + "." + f.Name))
                        {
                            FieldLoader.LoadField(kv.Value, f.Name, args.GetValue(kv.Key + "." + f.Name, ""));
                        }
                    }
                }
            }
            finally
            {
                FieldLoader.UnknownFieldAction = err1;
                FieldLoader.InvalidValueAction = err2;
            }
        }
Exemple #2
0
        public LaunchArguments(Arguments args)
        {
            if (args == null)
            {
                return;
            }

            foreach (var f in GetType().GetFields())
            {
                if (args.Contains("Launch" + "." + f.Name))
                {
                    FieldLoader.LoadField(this, f.Name, args.GetValue("Launch" + "." + f.Name, ""));
                }
            }
        }
Exemple #3
0
        public Settings(string file, Arguments args)
        {
            settingsFile = file;
            Sections = new Dictionary<string, object>()
            {
                { "Player", Player },
                { "Game", Game },
                { "Sound", Sound },
                { "Graphics", Graphics },
                { "Server", Server },
                { "Debug", Debug },
                { "Keys", Keys },
                { "Irc", Irc }
            };

            // Override fieldloader to ignore invalid entries
            var err1 = FieldLoader.UnknownFieldAction;
            var err2 = FieldLoader.InvalidValueAction;
            try
            {
                FieldLoader.UnknownFieldAction = (s, f) => Console.WriteLine("Ignoring unknown field `{0}` on `{1}`".F(s, f.Name));

                if (File.Exists(settingsFile))
                {
                    var yaml = MiniYaml.DictFromFile(settingsFile);

                    foreach (var kv in Sections)
                        if (yaml.ContainsKey(kv.Key))
                            LoadSectionYaml(yaml[kv.Key], kv.Value);
                }

                // Override with commandline args
                foreach (var kv in Sections)
                    foreach (var f in kv.Value.GetType().GetFields())
                        if (args.Contains(kv.Key + "." + f.Name))
                            FieldLoader.LoadField(kv.Value, f.Name, args.GetValue(kv.Key + "." + f.Name, ""));
            }
            finally
            {
                FieldLoader.UnknownFieldAction = err1;
                FieldLoader.InvalidValueAction = err2;
            }
        }
Exemple #4
0
        public Settings(string file, Arguments args)
        {
            settingsFile = file;
            Sections     = new Dictionary <string, object>()
            {
                { "Player", Player },
                { "Game", Game },
                { "Sound", Sound },
                { "Graphics", Graphics },
                { "Server", Server },
                { "Debug", Debug },
            };

            // Override fieldloader to ignore invalid entries
            var err1 = FieldLoader.UnknownFieldAction;
            var err2 = FieldLoader.InvalidValueAction;

            try
            {
                FieldLoader.UnknownFieldAction = (s, f) => Console.WriteLine("Ignoring unknown field `{0}` on `{1}`".F(s, f.Name));

                if (File.Exists(settingsFile))
                {
                    yamlCache = MiniYaml.FromFile(settingsFile, false);
                    foreach (var yamlSection in yamlCache)
                    {
                        object settingsSection;
                        if (yamlSection.Key != null && Sections.TryGetValue(yamlSection.Key, out settingsSection))
                        {
                            LoadSectionYaml(yamlSection.Value, settingsSection);
                        }
                    }

                    var keysNode = yamlCache.FirstOrDefault(n => n.Key == "Keys");
                    if (keysNode != null)
                    {
                        foreach (var node in keysNode.Value.Nodes)
                        {
                            if (node.Key != null)
                            {
                                Keys[node.Key] = FieldLoader.GetValue <Hotkey>(node.Key, node.Value.Value);
                            }
                        }
                    }
                }

                // Override with commandline args
                foreach (var kv in Sections)
                {
                    foreach (var f in kv.Value.GetType().GetFields())
                    {
                        if (args.Contains(kv.Key + "." + f.Name))
                        {
                            FieldLoader.LoadField(kv.Value, f.Name, args.GetValue(kv.Key + "." + f.Name, ""));
                        }
                    }
                }
            }
            finally
            {
                FieldLoader.UnknownFieldAction = err1;
                FieldLoader.InvalidValueAction = err2;
            }
        }