What is a good architecture for generating JavaScript from C #?

I have a set of objects in C # that are used to generate JavaScript. There is a web interface in which you select a ton of options, this creates a large object in C #. The object is then converted to JavaScript using a set of user-defined functions. This JavaScript is the core of our application, it runs on the server side using the V8 engine.

Currently, JavaScript is actually generated on the client, and this is a huge mess, impossible to verify, difficult to maintain, etc. It uses a ton for loops and string concatenation to generate JS. I would like to move this generation to C # and make it more verifiable. What are some good methods to create this JS? Is string concatenation an even better option?

+4
source share
1 answer

If the Javascript structure is extremely predictable (I suppose because you can use string concatenation), you can use a text-based template language such as NVelocity or DotLiquid . If this is completely unpredictable, you may need to create a complete Abstract syntax tree and generate code from it.

+2
source

All Articles