Exemplo n.º 1
0
        /// <summary>
        /// Gets the attribute value.
        /// </summary>
        /// <param name="instance">The instance.</param>
        /// <param name="propertyName">Name of the property.</param>
        /// <returns>
        /// The string value. Null if key does not exist
        /// </returns>
        public static string GetAttributeValue(this IAttributeContainer instance, [CallerMemberName] string propertyName = null)
        {
            var attributeName = instance.GetAttributeNameFor(propertyName);

            if (instance.ContainsAttributeFor(propertyName) == false)
            {
                return(null);
            }

            return(instance.Attributes[attributeName]);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Sets the attribute value.
        /// </summary>
        /// <param name="instance">The instance.</param>
        /// <param name="value">The value.</param>
        /// <param name="propertyName">Name of the property.</param>
        /// <returns>
        /// Sets the string value for the given property
        /// </returns>
        public static bool SetAttributeValue(this IAttributeContainer instance, string value, [CallerMemberName] string propertyName = null)
        {
            var attributeName = instance.GetAttributeNameFor(propertyName);
            var currentValue  = instance.GetAttributeValue(propertyName);

            if (currentValue != null && value == null)
            {
                instance.Attributes.Remove(attributeName);
                instance.NotifyAttributeChangedFor(propertyName);
                return(true);
            }

            if (Equals(currentValue, value))
            {
                return(false);
            }

            instance.Attributes[attributeName] = value;
            instance.NotifyAttributeChangedFor(propertyName);
            return(true);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Determines whether [contains attribute for] [the specified property name].
        /// </summary>
        /// <param name="instance">The instance.</param>
        /// <param name="propertyName">Name of the property.</param>
        /// <returns>
        ///   <c>true</c> if [contains attribute for] [the specified property name]; otherwise, <c>false</c>.
        /// </returns>
        public static bool ContainsAttributeFor(this IAttributeContainer instance, [CallerMemberName] string propertyName = null)
        {
            var attributeName = instance.GetAttributeNameFor(propertyName);

            return(instance.Attributes.ContainsKey(attributeName));
        }