Support for dynamic objects?

Apr 8, 2012 at 6:53 PM

Hi,

Is there a plan to support dynamic objects ?

I would like to write custom validation logic for dynamic objects at runtime. Probably Javascript.NET is using Reflection to get all the members in the object, it could check if the object is DynamicObject , and then call GetAllDynamicMembers() and complete the list.

Cheers.

Developer
Apr 10, 2012 at 12:18 AM

I don't think anyone is planning to do this, although it is a good idea.  Of course it could only work in the .Net 4.0 version, because DynamicObject is new.

Aug 19, 2013 at 1:58 PM
You could try the JContext object from the extensions library at https://github.com/danderson00/Noesis.Javascript.Extensions. There is currently no doco, but it's fairly basic.
Oct 23, 2013 at 11:38 PM
@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