How to dynamically generate javascript using ScriptSharp?

瘦欲@ 提交于 2019-12-11 03:08:32

问题


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!


回答1:


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.



来源:https://stackoverflow.com/questions/17282522/how-to-dynamically-generate-javascript-using-scriptsharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!