Exemple #1
0
        /// <summary>
        /// Gets the Global Attribute values for the specified key.
        /// </summary>
        /// <param name="key">The key.</param>
        /// <param name="rockContext">The rock context.</param>
        /// <returns></returns>
        public string GetValue(string key, RockContext rockContext)
        {
            string value;

            if (AttributeValues.TryGetValue(key, out value))
            {
                return(value);
            }

            var attributeCache = Attributes.FirstOrDefault(a => a.Key.Equals(key, StringComparison.OrdinalIgnoreCase));

            if (attributeCache == null)
            {
                return(string.Empty);
            }

            if (rockContext != null)
            {
                return(GetValue(key, attributeCache, rockContext));
            }

            using (var myRockContext = new RockContext())
            {
                return(GetValue(key, attributeCache, myRockContext));
            }
        }
Exemple #2
0
        /// <summary>
        /// Gets the optional boolean attribute value.
        /// </summary>
        /// <param name="attributeName">Name of the attribute.</param>
        /// <param name="defaultValue">Default value to return if the attribute is not found.</param>
        /// <returns>Boolean attribute value or default.</returns>
        public bool GetOptionalBooleanAttribute(string attributeName, bool defaultValue)
        {
            if (!AttributeValues.TryGetValue(attributeName, out var value))
            {
                return(defaultValue);
            }

            return(Convert.ToBoolean(value, CultureInfo.InvariantCulture));
        }
Exemple #3
0
        /// <summary>
        /// Gets the optional attribute value.
        /// </summary>
        /// <param name="attributeName">Name of the attribute.</param>
        /// <param name="defaultValue">The default value.</param>
        /// <returns>Value of the attribute or default value.</returns>
        public string GetOptionalAttribute(string attributeName, string defaultValue)
        {
            string value;

            if (!AttributeValues.TryGetValue(attributeName, out value))
            {
                value = defaultValue;
            }

            return(value);
        }
Exemple #4
0
        /// <summary>
        /// Gets the optional boolean attribute value. If whitespace, then returning <c>null</c>.
        /// </summary>
        /// <param name="attributeName">Name of the attribute.</param>
        /// <param name="defaultValue">Default value to return if the attribute is not found.</param>
        /// <returns>Boolean attribute value or default.</returns>
        public bool?GetOptionalBooleanAttribute(string attributeName, bool?defaultValue)
        {
            string value;

            if (!AttributeValues.TryGetValue(attributeName, out value))
            {
                //not defined, don't override default
                return(defaultValue);
            }

            if (StringHelpers.IsNullOrWhiteSpace(value))
            {
                //not default otherwise no difference between not defined and empty value.
                return(null);
            }

            return(Convert.ToBoolean(value, CultureInfo.InvariantCulture));
        }