Start a new topic

Class Indexers Compiled To JavaScript Syntax Issue

This is a simple class that uses an indexer to set values:


[Js(Name = "Object", Extern = true)]
 public class Tester
 {
     [Js(Name = "")]
     public extern dynamic this[string key] { get; set; }
 }

 

 

When using in C# code:


 Tester test = new Tester();
 test["tst1"] = "Hello";

 

 

It gets compiled in JavaScript as:

 

 var test = new Object();
 test.("tst1", "Hello");

 

Instead of something like it should:

 

var test = new Object();
test["tst1"] = "Hello";


JsDictionary and mainly JsInterface are designed for stronigly typed JS object wrapping:


For example DOM PropertyDescriptorMap is defined like this:


public class PropertyDescriptorMap : JsInterface

{

  public extern new PropertyDescriptor this[string s] { get; set; }

}


Also their use is very convenient thanks to C# 6 for collection initializers.


https://msdn.microsoft.com/en-us/library/bb384062.aspx

Either need to know what to make JsName for indexer or just remove JsName on the indexer definition... What do you think?

Login or Signup to post a comment