コード例 #1
0
ファイル: PropertyBag.cs プロジェクト: 3F/IeXod
        /// <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);
            }
        }