protected bool ContainsKey(string key, IPropertyBag propertyBag)
        {
            if (ContainsKeyInPropertyBag(key, propertyBag))
            {
                return(true);
            }

            IPropertyBag parent = propertyBag.GetParent();

            if (parent == null)
            {
                return(false);
            }

            return(ContainsKey(key, parent));
        }
        private TValue GetValueFromPropertyBagOrParents <TValue>(string key, IPropertyBag propertyBag)
        {
            if (propertyBag.Contains(key))
            {
                return(GetFromPropertyBag <TValue>(key, propertyBag));
            }

            IPropertyBag parent = propertyBag.GetParent();

            if (parent == null)
            {
                string exceptionMessage = string.Format(CultureInfo.CurrentCulture,
                                                        "There was no value configured for key '{0}' in a propertyBag with level '{1}' or above.",
                                                        key, propertyBag.Level);
                throw new ConfigurationException(exceptionMessage);
            }

            return(GetValueFromPropertyBagOrParents <TValue>(key, parent));
        }