Hi,
I've been searching and searching and have found various solutions on how to return an array from C#. In a previous post (http://social.msdn.microsoft.com/Forums/en-US/csharplanguage/thread/71e0d7ff-6531-4caa-9a0e-1cf02ec46318/) a user used this example:
namespace Example |
{ |
[ComVisible(true)] |
public interface ITesting |
{ |
string Test(); |
string[] TestArray(); |
} |
|
[ComVisible(true)] |
[ClassInterface(ClassInterfaceType.None)] |
public class Testing : ITesting |
{ |
[ComVisible(true)] |
public string Test() |
{ |
return "TestMethod"; |
} |
|
[ComVisible(true)] |
public string[] TestArray() |
{ |
string[] array = new string[3]; |
array[0] = "Test"; |
array[1] = "Array"; |
array[2] = "Method"; |
return array; |
} |
} |
} |
The answer that was suggested was to marshal the array in the interface as a safe array. This doesn't seem to work at all for JavaScript. What I get back I can examine in the VS JS debugger and see the value that I'm returning, but the object isn't a proper JS array so there is no length property and I could not retrieve the values using indexing (foo[0] always comes back as undefined).
After reading this article: http://blogs.msdn.com/ericlippert/archive/2003/09/22/53061.aspx I see that the array that is being returned to JavaScript is a VB type of array. Indeed, if I treat the returned object as a VBArray, then I can get at the information I need. I can also call foo.toArray() and get a proper JS array to use.
My question is, is there a way to return a proper JS array? Something that I can run through a loop
for (var i = 0; i < foo.length; i++) { var myString = foo[i]; }
like this?
Any help appreaciated.
Thanks,
--Aaron