Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question about custom indexer #161

Open
RusKnyaz opened this issue Sep 28, 2019 · 1 comment
Open

Question about custom indexer #161

RusKnyaz opened this issue Sep 28, 2019 · 1 comment
Labels

Comments

@RusKnyaz
Copy link

RusKnyaz commented Sep 28, 2019

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;
@paulbartrum
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants