Question

I'm looking for a way to dynamically generate javascript. I didn't find any information on this by browsing through Script#'s documentation, so here are my questions:

1) Is it possible to generate javascript code during runtime?

2) Is it possible to dynamically set a file name to which generated code would be saved to? Or can I get the generated code as a string?

A scenario would be: A user goes to a web site, enters a name in a text box, hits a button and a javascript is generated that would say alert("Hello name"). (which can be offered as a download)

I'm using the version I got through NuGet (0.7.5).

If it is possible, I would appreciate any hints or examples.

Thank you!

Was it helpful?

Solution

1) Yes, its possible. The script# compiler is packaged in ScriptSharp.dll and you can use the API it exposes. For an example of doing so, check out the sources of the script# msbuild tasks in the script# repository.

2) When you use the API, you effectively pass in a Stream - so you get the generated content, which you can use as you wish.

I'll recommend cloning the repository and using the "cc" branch to pick up the latest changes. The wiki on github has steps to build. 0.7.5 is a bit old now.

Hope that helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top