Question

Imagine you have two ScriptSharp classes like the following:

public class Person {
    public int Weight;
    public Name Name;
    public int Height;
}

public class Name { 
   public string FirstName;
   public string LastName;
}

How can I get ScriptSharp to generate the following in the output JS ?

var object1 = {
  weight: 0,
  name: {firstname: 'fname1', lastname: 'srn1'},
  height: 97
};

instead of

var object1 = {};
object1.weight = 0;
object1.height = 97;
Was it helpful?

Solution

Eventually there will be language support for object literals.

In the mean time you can use the technique demonstrated with the CustomDictionary class in one of the script# tests - see https://github.com/nikhilk/scriptsharp/blob/master/tests/TestCases/Expression/New/Code.cs.

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