/// <summary>
        /// The set.
        /// </summary>
        /// <param name="key">
        /// The key.
        /// </param>
        /// <param name="value">
        /// The value.
        /// </param>
        public bool SetProperty(TKey key, object value)
        {
            Property <TKey> property;

            if (this.DeleteNullProps && value == null)
            {
                return(this.dictionary.Remove(key));
            }

            if (this.dictionary.TryGetValue(key, out property))
            {
                if (!PropertyValueComparer.Compare(property.Value, value))
                {
                    property.Value = value;
                    return(true);
                }
                return(false);
            }

            property = new Property <TKey>(key, value);
            property.PropertyChanged += this.OnPropertyPropertyChanged;
            this.dictionary.Add(key, property);
            this.RaisePropertyChanged(key, value);

            return(true);
        }
        /// <summary>
        /// The set properties.
        /// </summary>
        /// <param name="values">
        /// The values.
        /// </param>
        /// <param name="expectedValues">
        /// expected values for properties, which we are going to change
        /// </param>
        /// <param name="debugMessage"></param>
        public bool SetPropertiesCAS(IDictionary <TKey, object> values, IDictionary <TKey, object> expectedValues, out string debugMessage)
        {
            debugMessage = string.Empty;
            bool changed;

            if (expectedValues == null || expectedValues.Count == 0)
            {
                this.SetProperties(values, out changed);
                return(changed);
            }

            foreach (var expectedValue in expectedValues)
            {
                var property = this.GetProperty(expectedValue.Key);
                if (property == null || !PropertyValueComparer.Compare(property.Value, expectedValue.Value))
                {
                    MakeCASDebugMessage(out debugMessage, property, expectedValue);
                    return(false);
                }
            }

            this.SetProperties(values, out changed);
            return(changed);
        }
        /// <summary>
        /// The set properties.
        /// </summary>
        /// <param name="values">
        ///     The values.
        /// </param>
        /// <param name="expectedValues">
        ///     The expected values for properties in order to apply CAS.
        /// </param>
        /// <param name="valuesChanged">informs whether values were really changed</param>
        /// <param name="debugMessage"></param>
        public bool SetPropertiesCAS(IDictionary values, IDictionary expectedValues, ref bool valuesChanged, out string debugMessage)
        {
            debugMessage = string.Empty;
            bool changed;

            if (expectedValues == null || expectedValues.Count == 0)
            {
                this.SetProperties(values, out changed);
                valuesChanged |= changed;
                return(true);
            }

            foreach (DictionaryEntry expectedValue in expectedValues)
            {
                var property = this.GetProperty((TKey)expectedValue.Key);
                if ((property == null && expectedValue.Value != null) || (property != null && !PropertyValueComparer.Compare(property.Value, expectedValue.Value)))
                {
                    MakeCASDebugMessage(out debugMessage, property, new KeyValuePair <TKey, object>((TKey)expectedValue.Key, expectedValue.Value));
                    return(false);
                }
            }

            this.SetProperties(values, out changed);
            valuesChanged |= changed;
            return(true);
        }