C# class attributes not accessible in Javascript

早过忘川 提交于 2019-12-02 12:05:18
Alan Yao - MSFT

I believe you need to define the method name starting with a lower case character.

For example: change GetIPAddress to getIPAddress.

I tested it on my side and found if I use the upper case name 'GetIPAddress', it won't work. But if I use getIPAddress, it works.

And after I read kangax's explanation in this thread, I think it makes sense.

[Update]

Since it still doesn't work after you make the change on method name, I think the issue should be related to how you expose the windows runtime object. I guess you simply defined the DeviceInformation class and tried to use it in the same project.

First, we need to create a separate windows universal windows runtime component project.

The c# class DeviceInformation should be put into this project. Keep the same code.

Then, in your universal app project, add reference to the windows runtime component and keep rest code to consume the windows runtime object.

[Update 2]

Just noticed an interesting behavior in VS. No matter if the Method name we defined in C# is starting with uppercase or lowercase, the visual studio intellisense shows the lowercase, so the method name will be automatically converted when we try to use it in js.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!