Exemplo n.º 1
0
 /// <summary>
 /// Wraps this <see cref="HoconValue"/> into a new <see cref="Config"/> object at the specified key.
 /// </summary>
 /// <param name="key">The key designated to be the new root element.</param>
 /// <returns>A <see cref="Config"/> with the given key as the root element.</returns>
 public Config AtKey(string key)
 {
     var o = new HoconObject();
     o.GetOrCreateKey(key);
     o.Items[key] = this;
     var r = new HoconValue();
     r.Values.Add(o);
     return new Config(new HoconRoot(r));
 }
Exemplo n.º 2
0
        public void Merge(HoconObject other)
        {
            var thisItems = Items;
            var otherItems = other.Items;

            foreach (var otherItem in otherItems)
            {
                if (thisItems.ContainsKey(otherItem.Key))
                {
                    //other key was present in this object.
                    //if we have a value, just ignore the other value, unless it is an object
                    var thisItem = thisItems[otherItem.Key];

                    //if both values are objects, merge them
                    if (thisItem.IsObject() && otherItem.Value.IsObject())
                    {
                        thisItem.GetObject().Merge(otherItem.Value.GetObject());
                    }
                }
                else
                {
                    //other key was not present in this object, just copy it over
                    Items.Add(otherItem.Key,otherItem.Value);
                }
            }
        }