jurassic icon indicating copy to clipboard operation
jurassic copied to clipboard

Question about custom indexer

Open RusKnyaz opened this issue 6 years ago • 1 comments
trafficstars

Can I expose object's indexer with string key?

Say, I implemented the class:

class ClrObjectInstance : ObjectInstance
{
//... ctor and other things here
        public object this[string name]
        {
            get => "hello";
            set {}//do something here
        }
}

and I want to the indexer be called when somewhere in JS the following code executed:

customObject['zoom'] = 1;

RusKnyaz avatar Sep 28 '19 07:09 RusKnyaz

FYI in javascript customObject['zoom'] = 1; is the same as customObject['zoom'] = 1.

Unfortunately, if you write an indexer like that, it won't get called. You can override GetMissingPropertyValue to implement the getter, but I can't think of an easy way to do the setter off the top of my head.

paulbartrum avatar Sep 29 '19 21:09 paulbartrum