public static string SerializeRuleDictionary(CssRuleDictionary rules) { bool useWhitespace = true; var sb = new StringBuilder(); foreach (string currSelector in rules.GetSelectors()) { sb.Append(currSelector); if (useWhitespace) { sb.AppendLine(); sb.AppendLine("{"); } else sb.Append(" {"); foreach (CssDeclaration currDeclaration in rules[currSelector]) { string declaration = currDeclaration.Property + ":" + currDeclaration.Value + ";"; if (useWhitespace) sb.AppendLine("\t" + declaration); else sb.Append(declaration); } if (useWhitespace) sb.AppendLine("}"); else sb.Append("} "); } return sb.ToString(); }
public static CssRuleDictionary ParseRuleDictionary(string cssSource) { CssRuleDictionary dictionary = new CssRuleDictionary(); dictionary.AddRules(ParseRules(cssSource)); return dictionary; }