Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><code>IronPython.Runtime.List</code> implements the following interfaces:</p> <pre><code>IList, ICollection, IList&lt;object&gt;, ICollection&lt;object&gt;, IEnumerable&lt;object&gt;, IEnumerable </code></pre> <p>so you can cast to one of this types an then turn into a <code>List&lt;string&gt;</code>.</p> <pre><code>List&lt;string&gt; result = ((IList&lt;object&gt;)op.Invoke(method)).Cast&lt;string&gt;().ToList(); </code></pre> <hr> <p>BTW, maybe you are aware of it, but you can also use .NET types in IronPython e.g.:</p> <pre><code>from System.Collections.Generic import * class MyClass(object): def myMethod(self): return List[str](['a','list','of','strings']) </code></pre> <p>here <code>myMethod</code> returns directly a <code>List&lt;string&gt;</code></p> <hr> <p><strong>EDIT:</strong></p> <p>Given that you're using .net 2.0 (so no LINQ) you have two options (IMO):</p> <p><strong>1.</strong> Cast to <code>IList&lt;object&gt;</code> and use it:</p> <pre><code>IList&lt;object&gt; result = (IList&lt;object&gt;)op.Invoke(method); </code></pre> <p><strong>PROs</strong>: no loop required, you will use the same object instance returned by the python script.<br> <strong>CONs</strong>: no type safety (you will be like in python, so you can add also a non-string to the list)</p> <p><strong>2.</strong> Convert to a <code>List&lt;string&gt;</code>/<code>IList&lt;string&gt;</code> :</p> <pre><code>IList&lt;object&gt; originalResult = (IList&lt;object&gt;)op.Invoke(method); List&lt;string&gt; typeSafeResult = new List&lt;string&gt;(); foreach(object element in originalResult) { typeSafeResult.Add((string)element); } </code></pre> <p><strong>PROs</strong>: type safe list (you can add only strings).<br> <strong>CONs</strong>: it requires a loop, and the converted list is a new instance (not the same returned by the script)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload