C# MSScriptControl Make Array Visible

467 Views Asked by At

I am using MS ScriptControl to add scripting to my application. Everything works fine except when I have a class that is visible to the script engine that has an array. I can't access the array elements from the script.

Example C# class:

using System.Runtime.InteropServices;

namespace my_app
{
    [ComVisible(true)]
    public class test
    {
        public string this_works = "Hello";
        public string[] no_workey = new string[4];

        public test()
        {
            no_workey[0] = "I";
            no_workey[1] = "can't";
            no_workey[2] = "see";
            no_workey[3] = "you!";
        }
    }
}

I add the class to the script engine:

script.AddObject("test", new test(), true);

I've built in some functionality to print an object. Here are my results:

test.this_works   ->  "Hello"
test.no_workey    -> System.String[]
test.no_workey[0] -> 'test.no_workey.0' is null or not an object.

Does anyone know how I can do this? Thanks!

0

There are 0 best solutions below