views:

137

answers:

3

I have a javascript based library and would like to generate some C# classes for it. Unfortunately, I do not know T4 at all, so I may not have included information you need to answer this question. please comment, and I will edit as needed.

Thanks!

A: 

Yes, you can write a T4 template that creates C# classes from JavaScript class definitions. But there is nothing in T4 that helps you with doing so. A T4 template is essentially just a C# script that is executed by Visual Studio whenever the template file is modified.

dtb
what do you mean by "there is nothing in T4" that helps you with doing so? Regent, above suggested that "you'll need to parse those Javascript files somehow by yourself"-- which seems to me to be a pretty lousy experience.
MedicineMan
@MedicineMan: as dtb said, there is little what Visual Studio and .NET Framework can help you with to transform JavaScript class definitions out of the box.
Regent
A: 

Well, with T4 templates you can generate pretty much anything.

But you'll need to parse those JavaScript files somehow by yourself within T4.

Regent
+1  A: 

Three Routes to try in order of niceness

a) Use CodeModel in Visual Studio 2008 or later to parse the javascript source code
b) Jscript.NET compiler to parse your code / or Eval() objects from it then walk over that code
c) Use RegEx to parse on your own

Please Drop me a line at tfischer AT tangible . DE. I am doing this for C# anyways right now an can add js for sure.

Tim Fischer