Exemple #1
0
        public void SetValue <T>(string key, T value)
        {
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }

            int index = key.IndexOf('.');

            if (index != -1)
            {
                string       childName = key.Substring(0, index);
                ConfigSource child     = GetChild(childName);
                if (child == null)
                {
                    child = AddChild(childName);
                }

                key = key.Substring(index + 1);
                child.SetValue(key, value);
                return;
            }

            if (Equals(default(T), value) && keyValues.ContainsKey(key))
            {
                keyValues.Remove(key);
            }
            else
            {
                keyValues[key] = Convert.ToString(value, CultureInfo.InvariantCulture);
            }
        }
        public void TestString()
        {
            ConfigSource config = new ConfigSource();

            config.SetValue("key", "value");

            Assert.AreEqual("value", config.GetString("key"));
        }
        public void TestInt64()
        {
            ConfigSource config = new ConfigSource();

            config.SetValue("key", 64L);

            Assert.AreEqual(64L, config.GetInt32("key"));
        }
        public void TestIn32()
        {
            ConfigSource config = new ConfigSource();

            config.SetValue("key", 32);

            Assert.AreEqual(32, config.GetInt32("key"));
        }
        public void GetChildValue()
        {
            ConfigSource config = new ConfigSource();
            ConfigSource child  = config.AddChild("test.child");

            child.SetValue("value", 32);

            int value = config.GetInt32("test.child.value");

            Assert.AreEqual(32, value);
        }
        public void Load(ConfigSource config, Stream input)
        {
            if (!input.CanRead)
            {
                throw new ArgumentException("Cannot read from the stream.", "input");
            }

            Util.Properties properties = new Util.Properties();
            properties.Load(input);
            foreach (KeyValuePair <object, object> pair in properties)
            {
                config.SetValue((string)pair.Key, (string)pair.Value);
            }
        }
Exemple #7
0
        public object Clone()
        {
            ConfigSource config = (ConfigSource)Activator.CreateInstance(GetType());

            foreach (KeyValuePair <string, string> pair in keyValues)
            {
                config.SetValue(pair.Key, pair.Value);
            }
            foreach (ConfigSource child in children)
            {
                config.children.Add((ConfigSource)child.Clone());
            }
            return(config);
        }