示例#1
0
 /// <summary>
 /// Set some style properties from an object to an element
 /// </summary>
 public static HElement Css(this HElement element, Object properties)
 {
     if (element != null && properties != null)
     {
         var styles = element.Css();
         if (properties is IDictionary <String, String> )
         {
             foreach (var prop in ((IDictionary <String, String>)properties))
             {
                 styles[ConvertCamelNameToStyleName(prop.Key)] = prop.Value;
             }
         }
         else
         {
             foreach (var member in properties.GetType().GetMembers().Where(m => m is PropertyInfo || m is FieldInfo))
             {
                 String mName = ConvertCamelNameToStyleName(member.Name.Replace("_", "-"));
                 if (member is PropertyInfo)
                 {
                     styles[mName] = Convert.ToString(((PropertyInfo)member).GetValue(properties, null));
                 }
                 else if (member is FieldInfo)
                 {
                     styles[mName] = Convert.ToString(((FieldInfo)member).GetValue(properties));
                 }
             }
         }
         SetStyle(element, styles);
     }
     return(element);
 }
示例#2
0
        /// <summary>
        /// Set a style property in the element
        /// </summary>
        public static HElement Css(this HElement element, String propertyName, String value)
        {
            if (element == null || String.IsNullOrWhiteSpace(propertyName))
            {
                return(element);
            }
            var styles = element.Css();

            styles[ConvertCamelNameToStyleName(propertyName)] = value;
            SetStyle(element, styles);
            return(element);
        }
示例#3
0
        /// <summary>
        /// Get the value of a style property in the element
        /// </summary>
        public static String Css(this HElement element, String propertyName)
        {
            if (element == null || String.IsNullOrWhiteSpace(propertyName))
            {
                return(String.Empty);
            }
            var    styles = element.Css();
            String result;

            if (styles.TryGetValue(ConvertCamelNameToStyleName(propertyName), out result))
            {
                return(result);
            }
            return(String.Empty);
        }
示例#4
0
        /// <summary>
        /// Get the values of a list of style properties in the element
        /// </summary>
        public static IEnumerable <String> Css(this HElement element, String[] propertyNames)
        {
            var styles = element.Css();

            if (propertyNames != null)
            {
                foreach (var propertyName in propertyNames)
                {
                    if (String.IsNullOrWhiteSpace(propertyName))
                    {
                        continue;
                    }
                    String result;
                    if (styles.TryGetValue(ConvertCamelNameToStyleName(propertyName), out result))
                    {
                        yield return(result);
                    }
                    else
                    {
                        yield return(String.Empty);
                    }
                }
            }
        }