[英]How to get StyleRules as a string output using ExCSS Parser
I'm using ExCSS to parse and manipulate a stylesheet string.我正在使用ExCSS来解析和操作样式表字符串。 So far so good.到现在为止还挺好。
But I can't find any documentation on how to convert the manipulated style rules into a string.但是我找不到任何关于如何将操纵的样式规则转换为字符串的文档。
Although the code may not be relevant to this question, this is what I'm doing:虽然代码可能与这个问题无关,但这就是我正在做的:
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();
}
Thank you for your help!感谢您的帮助!
Turns out the ToString()
method needs to be called on the ExCSS.StyleSheet instance and I was calling it on the StyleRules collection.结果证明需要在 ExCSS.StyleSheet 实例上调用ToString()
方法,而我在 StyleRules 集合上调用它。
You only need to do the following (as per my sample code in the question above):您只需要执行以下操作(按照我在上面问题中的示例代码):
return stylesheet.ToString();
I hope this answer might save someone else's time.我希望这个答案可以节省别人的时间。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.