internal static void PromoteAllCachedDefaultValues(DependencyObject owner)
        {
            FrugalMapBase map = _defaultValueFactoryCache.GetValue(owner);

            if (map != null)
            {
                // Iterate through all the items in the map (each representing a DP)
                // and promote them to locally-set.
                map.Iterate(null, _promotionCallback);
            }
        }
        // Because the frugalmap is going to be stored in an uncommon field, it would get boxed
        // to avoid this boxing, skip the struct and go straight for the class contained by the
        // struct.  Given the simplicity of this scenario, we can get away with this.
        private object GetCachedDefaultValue(DependencyObject owner, DependencyProperty property)
        {
            FrugalMapBase map = _defaultValueFactoryCache.GetValue(owner);

            if (map == null)
            {
                return(DependencyProperty.UnsetValue);
            }

            return(map.Search(property.GlobalIndex));
        }
        /// <summary>
        ///     This method causes the DefaultValue cache to be cleared ensuring
        ///     that CreateDefaultValue will be called next time this metadata
        ///     is asked to participate in the DefaultValue factory pattern.
        ///
        ///     This is internal so it can be accessed by subclasses of
        ///     DefaultValueFactory.
        /// </summary>
        internal void ClearCachedDefaultValue(DependencyObject owner, DependencyProperty property)
        {
            FrugalMapBase map = _defaultValueFactoryCache.GetValue(owner);

            if (map.Count == 1)
            {
                _defaultValueFactoryCache.ClearValue(owner);
            }
            else
            {
                map.RemoveEntry(property.GlobalIndex);
            }
        }
        /// <summary>
        /// Removes all cached default values on an object.  It iterates though
        /// each one and, if the cached default is a Freezable, removes its
        /// Changed event handlers. This is called by DependencyObject.Seal()
        /// for Freezable type owners.
        /// </summary>
        /// <param name="owner"></param>
        internal static void RemoveAllCachedDefaultValues(Freezable owner)
        {
            FrugalMapBase map = _defaultValueFactoryCache.GetValue(owner);

            if (map != null)
            {
                // Iterate through all the items in the map (each representing a DP)
                // and remove the promotion handlers
                map.Iterate(null, _removalCallback);

                // Now that they're all clear remove the map.
                _defaultValueFactoryCache.ClearValue(owner);
            }
        }
        private void SetCachedDefaultValue(DependencyObject owner, DependencyProperty property, object value)
        {
            FrugalMapBase map = _defaultValueFactoryCache.GetValue(owner);

            if (map == null)
            {
                map = new SingleObjectMap();
                _defaultValueFactoryCache.SetValue(owner, map);
            }
            else if (!(map is HashObjectMap))
            {
                FrugalMapBase newMap = new HashObjectMap();
                map.Promote(newMap);
                map = newMap;
                _defaultValueFactoryCache.SetValue(owner, map);
            }

            map.InsertEntry(property.GlobalIndex, value);
        }