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

Optional arguments

Jul 21, 2014 at 11:32 AM
Currently I'm in the process of migrating my own VBScript ScriptingHost integration to ClearScript.

In my implementation the following script-exposed C# code run successfully:
public string Foo(
    string a,
    [Optional]object argument0,
    [Optional]object argument1)
    // ...
This could be called from VBScript with either one, two or three parameters. The reason is the "Optional" attribute which are attached to the second and third parameter.

When using it with ClearScript and the VBScript engine, the calling of the method results in and 0x80020101 error.

My questions:

Is it possible to use optional parameters with ClearScript? If yes, how would I do it?
Jul 21, 2014 at 11:45 AM
Edited Jul 21, 2014 at 11:45 AM
OMG, this is so simple. Shame on me!

When writing this one:
public string Foo(
    string a,
    object argument0 = null,
    object argument1 = null)
    // ...
It runs like a charm!

I.e. simply using the standard C# way of declaring optional parameters is totally sufficient.

(Instead of "null" I also could have used "Missing.Value" to keep my inner logic the same as in my VBScript engine)
Marked as answer by UweKeim on 7/21/2014 at 3:49 AM
Jul 21, 2014 at 2:07 PM
We're glad you found a solution! Thanks for posting it!