Quantcast
Channel: ClearScript
Viewing all articles
Browse latest Browse all 2297

New Post: Problem with C# enumerables (generic, arrays, whatever) with vbscript

$
0
0
I have a List<ISomeInterface> in c# that I am trying to work with in vbscript.

While I can access some methods of the list (Count seems to work), I cannot enumerate it, no matter what I seem to try.

I have attempted For Each, but the list is not seen as a container so that fails.
I have attempted indexing like so
  For i = 0 to someList.Count
     myLog.Info "Name: " & someList.ElementAt(i).Name
  Next
which fails, 'ElementAt' is not recognized "Object doesn't support this property or method"

someList[i] fails with "expected end of statement" (apparently invalid vbscript)
someList(i) fails with the "Object doesnt support this property or method" (not unexpected)

I read the discussion on dealing with arrays in vbscript here https://clearscript.codeplex.com/discussions/539210

and see my comment about ElementAt above. Also, I tried exporting the list as an array instead, and that had simmilar issues.

Here is how I am calling it... Please note that I must use .Execute and not .Evaluate
         using (ScriptEngine engine = new Microsoft.ClearScript.Windows.VBScriptEngine())
         {
            engine.AddHostObject("myLog", Logger.Instance);
            engine.AddHostObject("someList", someList);

            try
            {
               engine.Execute(scriptText_);
            }
            catch (ScriptEngineException sce)
            {
               Log.Error("The Script threw an exception.  Details: {0}", sce.Format());
               return false;
            }
         }
Any help would be appreciated.

Viewing all articles
Browse latest Browse all 2297

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>