예제 #1
0
 public CssRule this[String ruleName]
 {
     get
     {
         CssRule rule = null;
         rules.TryGetValue(ruleName.ToLowerInvariant(), out rule);
         return(rule);
     }
 }
예제 #2
0
 public RuleCssParser(String ruleCss)
 {
     if (!String.IsNullOrEmpty(ruleCss))
     {
         MatchCollection MatchList = rStyles.Matches(ruleCss);
         foreach (Match item in MatchList)
         {
             //Check for nulls
             if (item != null && item.Groups != null &&
                 item.Groups[SelectorKey] != null &&
                 item.Groups[SelectorKey].Captures != null &&
                 item.Groups[SelectorKey].Captures[0] != null &&
                 !String.IsNullOrEmpty(item.Groups[SelectorKey].Value))
             {
                 CssRule rule = new CssRule(item.Groups[SelectorKey].Captures[0].Value.Trim());
                 for (int i = 0; i < item.Groups[NameKey].Captures.Count; i++)
                 {
                     String className = item.Groups[NameKey].Captures[i].Value;
                     String value     = item.Groups[ValueKey].Captures[i].Value;
                     //Check for null values in the properies
                     if (!String.IsNullOrEmpty(className) && !String.IsNullOrEmpty(value))
                     {
                         className = className.Trim();
                         value     = value.Trim();
                         //One more check to be sure we are only pulling valid css values
                         if (!String.IsNullOrEmpty(className) && !String.IsNullOrEmpty(value) && value != ":")
                         {
                             rule[className] = value;
                         }
                     }
                 }
                 rules.Add(rule.Name.ToLowerInvariant(), rule);
             }
         }
     }
 }