如何使用ExCSS解析器将StyleRules作为字符串输出

如何使用ExCSS解析器将StyleRules作为字符串输出

问题描述:

我使用ExCSS来解析和处理样式表字符串。到现在为止还挺好。如何使用ExCSS解析器将StyleRules作为字符串输出

但我找不到有关如何将操纵风格规则转换为字符串的任何文档。

尽管代码可能不是有关这个问题,这是我在做什么:

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(); 
} 

谢谢您的帮助!

原来需要在ExCSS.StyleSheet实例上调用ToString()方法,我在StyleRules集合上调用它。

你只需要做以下(按照上面的问题,我的示例代码):

return stylesheet.ToString(); 

我希望这个答案可能挽救别人的时间。