This project has moved and is read-only. For the latest updates, please go here.

Returning a derived type with VBScript

May 23, 2014 at 6:55 AM
Edited May 23, 2014 at 7:47 AM
Currently I'm in the process of migrating my own VBScript ScriptingHost integration to ClearScript.

I discovered that the behaviour of ClearScript differs in (at least ;-) one way:

When returning a type from a function that is actually the derived type, ClearScript does not see the members of that derived type.

public class Base
    public int A() { return 1; }

public class Derived : Base
    public int B() { return 2; }
Using this class somewhat like:
public Base GetObject() { return new Derived(); }
And then inside my script:
dim x
set x = MyObject.GetObject();

x.B() ' Here it throws "Object does not support property or method".
I've also tried engine.AllowReflection = true; without any success.

While this behaviour is what I would expect from C# code, I would love to have ClearScript behave like my own VBScript ScriptingHost implementation and see all members, no matter what type the engine thinks it sees.

My question is:

Can I configure ClearScript to also make the members of derived classes be visible to the script, even when only dealing with a base type?
May 23, 2014 at 12:31 PM

The quick answer: You can do this:
public Base GetObject() { return new Derived(); }
For more information, please see here.

Good luck!
May 23, 2014 at 1:13 PM
Awesome, thanks a lot.

Any chance to globally switch the default behaviour to always expose the runtime type?
May 24, 2014 at 3:55 PM
Unfortunately ClearScript doesn't have such an option at this time.
Jun 11, 2014 at 3:34 AM
We've posted an update that includes the new property ScriptEngine.DisableTypeRestriction for controlling this behavior at the engine level.
Jun 11, 2014 at 6:29 AM
Incredible! This is a huge improvement for me and helps me a lot.

Thank you very much!