Skip to content

Creating objects and arrays

paulbartrum edited this page Apr 26, 2016 · 4 revisions

It is very common in JavaScript to create "property bags", objects with an arbitrary set of properties, like this:

var segment = {
  type: "Feature",
  properties: {},
  geometry: {
    type: "LineString",
    coordinates: [
      [ -37.3, 121.5 ],
      [ -38.1, 122.6 ]
    ]
  }
}

Here's the equivalent C# code to create the same object:

var segment = engine.Object.Construct();
segment["type"] = "Feature";
segment["properties"] = engine.Object.Construct();
var geometry = engine.Object.Construct();
geometry["type"] = "LineString";
geometry["coordinates"] = engine.Array.Construct(
  engine.Array.New(new object[] { -37.3, 121.5 }),
  engine.Array.New(new object[] { -38.1, 122.6 })
);
segment["geometry"] = geometry;

Next tutorial: Using the console API

Clone this wiki locally