Quantcast
Channel: Javascript .NET
Viewing all articles
Browse latest Browse all 137

New Post: Support for dynamic objects?

$
0
0
@danderson00, thanks for the reference, but those extensions make it so you can access the JSContext in a dynamic way, not so that you can handle javascript member access on C# objects in a dynamic way.
Still a good project to know about though.

@valerianot, I wanted the same feature as you so I had a look at the noesis source code and it turned out not too difficult to implement a simple solution.
I only had to change the GetProperty and SetProperty methods of JavascriptExternal to get what I wanted.
I didn't implement it for DynamicObject because it would have been more complex, and also because the hacky way I've done it will work for .NET 2.0 as well.

Here's the updated JavascriptExtensions.cpp file:
http://BlindAudioGames.com/downloads/JavascriptExternal.cpp

Basically you implement these 2 methods on your C# object and if you access members of that object via javascript and it doesn't have the member you tried to access it will call these methods so you can handle it in a dynamic way:
public object JavascriptGetMember(string name)
public void JavascriptSetMember(string name, object value)

Hope that helps someone.
Ian Reed

Viewing all articles
Browse latest Browse all 137

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>