c# - Is there a Css writer for .net? -
i've noticed microsoft has implemented csstextwriter internal
internal sealed class csstextwriter : textwriter { .... }
is there css writer .net that?
for example write code such as:
csstextwriter writer = new csstextwriter(textwriter); writer.writebegincssrule("p"); writer.writeattribute("font-family", "arial,liberation sans,dejavu sans,sans-serif"); writer.writeendcssrule();
the above code output stream follows:
p { font-family: arial,liberation sans,dejavu sans,sans-serif; }
dotless http://www.dotlesscss.org/ looks job, bit needed single clss
i wrapped calls internal microsoft class (yes naughty , might go away in future releases of .net etc....)
public class csstextwriter { public csstextwriter(textwriter writer) { if (writer == null) { throw new argumentnullexception("writer"); } this.writer = writer; this.initialize(); } /// <summary> /// gets writer. /// </summary> /// <value> /// writer. /// </value> public textwriter writer { get; private set; } /// <summary> /// gets or sets internal css text writer. /// </summary> /// <value> /// internal css text writer. /// </value> private object internalcsstextwriter { get; set; } public void writebegincssrule(string selector) { this.internalcsstextwriter.invokemethod("writebegincssrule", new[] { selector }); } public void writeendcssrule() { this.internalcsstextwriter.invokemethod("writeendcssrule"); } public void writeattribute(string name, string value) { this.internalcsstextwriter.invokemethod("writeattribute", new[] { name, value }, new type[] { typeof(string), typeof(string) }); } public void write(string value) { this.internalcsstextwriter.invokemethod("write", new[] { value }, new type[] { typeof(string) }); } public void writeattribute(htmltextwriterstyle key, string value) { this.internalcsstextwriter.invokemethod("writeattribute", new object[] { key, value }, new type[] { typeof(htmltextwriterstyle), typeof(string) }); } private void initialize() { type internaltype = typeof(system.web.ui.htmltextwriter).assembly.gettype("system.web.ui.csstextwriter"); constructorinfo ctor = internaltype.getconstructors(bindingflags.instance | bindingflags.public)[0]; this.internalcsstextwriter = ctor.invoke(new[] { this.writer }); } }
Comments
Post a Comment