我使用ExCSS来解析和操作样式表字符串。到目前为止一切都很好。
但我找不到任何关于如何将操纵样式规则转换为字符串的文档。
虽然代码可能与此问题无关,但这正是我所做的:
private string ManipulateCSS(string styles)
{
ExCSS.Parser parser = new ExCSS.Parser();
var stylesheet = parser.Parse(styles);
// here I perform specific manipulations
// which are not relevant to this question...
stylesheet.StyleRules
.SelectMany(r => r.Declarations)
.Where(d => d.Name == "<something>"
...
...
// Now, the next line is where I'm having issues:
// how to return the whole string with styles out of this ExCSS parser?
return stylesheet.StyleRules.ToString();
}
感谢您的帮助!
答案 0 :(得分:1)
原来需要在ExCSS.StyleSheet实例上调用ToString()
方法,我在StyleRules集合上调用它。
您只需执行以下操作(根据上述问题中的示例代码):
return stylesheet.ToString();
我希望这个答案可以节省别人的时间。