Пример #1
0
        /// <summary>
        /// Add a single property to the collection.
        /// </summary>
        /// <remarks>If the property is defined and identical in the parent, no action is taken.</remarks>
        /// <param name="key">The property key.</param>
        /// <param name="value">The property value.</param>
        public void AddProperty(string key, string value)
        {
            string currentValue;

            if (_properties.TryGetValue(key, out currentValue))
            {
                // We've already seen the property here, update value if different
                if (currentValue != value)
                {
                    _properties[key] = value;
                }
            }
            else if (_parent != null && _parent.TryGetValue(key, out currentValue))
            {
                // The parent has the property, only add if different
                if (currentValue != value)
                {
                    _properties.Add(key, value);
                }
            }
            else
            {
                // No one has the property, just add it.
                _properties.Add(key, value);
            }
        }
Пример #2
0
        public bool TryGetValue(string key, out string value)
        {
            if (_properties.TryGetValue(key, out value))
            {
                return(true);
            }

            return(_parent?.TryGetValue(key, out value) == true);
        }