Looking for existing, proven, solutions for quickly generating a client-side javascript object model that represents an existing c# object. I imagine there is a T4 template or some other approach out there but I lack the terminology to find it. I'm not talking about serialization to get the JSON representation of an existing c# object instance or anything to do with deserialization. I simply want to generate the javascript object model's for 20+ c# objects and I want to be able to re-generate them at a moments notice if the c# code changes.
Over-simplified example of what I'm looking for:
C# code:
[Serializable()]
public class Cat
{
public string Name { get; set; }
public string Breed { get; set; }
}
Javascript object model to be generated:
function Cat()
{
this.Name = "";
this.Breed = "";
}
@Baszz
JSON is a text-based standard for data interchange and that's not what I'm looking for. I need to generate a client-side API of 20+ objects that I can put in a javascript file and link that script to my various web pages.
The JavaScriptSerializer can spit out a string like below from a c# object:
{ "Name": "Hayden", "Breed": "Rabbit” }
But this is not the same thing as:
function Cat()
{
this.Name = "";
this.Breed = "";
}
- The JSON string is not a named function.
- All elements are quoted and in the JSON format which would require manual parsing of the string to get it into the format I need.
- You cannot new-up an instance of Cat like below because of #1
var myCat = new Cat();
Not a lot of comments so I’m guessing everyone does this by hand or not at all. Looking at creating my own T4 template to parse the c# files and generate my client-side API’s.