I want to emit just debugger; to javascript from c# script sharp code. I realize I could write Script.Literal("debugger"). I'd rather not use Script.Literal unless absolutely needed. I'd prefer to write something like Debugger.Break(); in c# with the emitted javascript being just debugger; Is there some sort of attribute that will let me do this if I create an Imported Library?
This is quite a hack, but it works. You gotta get creative when what you want to do isn't officially supported, right?
It's based on the way Script.Alert works and makes use of the [ScriptAlias] attribute to include a JavaScript comment. Luckily ScriptAliasAttribute passes along the value provided exactly and doesn't sanitize it in any way.
namespace MyNamespace
{
[GlobalMethods]
[IgnoreNamespace]
[Imported]
public static class Debugger
{
[ScriptAlias("debugger;//")]//must comment out ();
public static void Break()
{
//this outputs - debugger;//();
}
}
}
So, using the above code, you can write Debugger.Break(); in your C# code, and you'll get debugger;//(); in the JavaScript emitted. A little ugly, but it works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With