Hello!
Here's what's going on. In your script code, the expression
When you change the type to
Note that
No, this is by design. ClearScript's goal is to provide C#-like access to .NET types. .NET supports things like generic and overloaded methods, and C# method binding relies on static analysis of the method arguments. Script languages don't support static typing, so ClearScript simulates it with a feature called type restriction, which allows C#-like method binding to take place at runtime.
You can use ClearScript's
You can also use the engine's
Good luck!
Here's what's going on. In your script code, the expression
Me.MyList
is of the managed type IList<Item>
. This type has an indexer that is actually an indexed property named "Item". ClearScript supports indexed properties, but it requires the following syntax:// JavaScriptvar value = Me.MyList.Item.get(index); // or Me.MyList.Item(index) Me.MyList.Item.set(index, value);
List<Item>
, you enable ClearScript's special treatment of objects that implement IList
. This feature supports array-like access from script code:// JavaScriptvar value = Me.MyList[index]; Me.MyList[index] = value;
IList<T>
is not derived from IList
and therefore doesn't trigger this feature.
It looks like that engine.Execute() uses the static declaration type instead of the actual type of the object Me.MyList. Is this a defect ?
No, this is by design. ClearScript's goal is to provide C#-like access to .NET types. .NET supports things like generic and overloaded methods, and C# method binding relies on static analysis of the method arguments. Script languages don't support static typing, so ClearScript simulates it with a feature called type restriction, which allows C#-like method binding to take place at runtime.
Is there a way to configure ClearScript to fix this problem?
You can use ClearScript's
ScriptMemberAttribute
to expose the runtime type of a given member:[ScriptMember(ScriptMemberFlags.ExposeRuntimeType)] public IList<Item> MyList = new List<Item> { new Item(), new Item(), new Item() };
DisableTypeRestriction
property to turn off type restriction globally, but doing so can break some method invocation scenarios.Good luck!