Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It seems that you want to have typesafety and LINQ support while simultaneously not defining the types involved - which you can't do in C#.</p> <p>One option is providing overloads of <code>Execute</code> that rather than taking <code>object ctx</code> can take the appropriate <code>IEnumerable&lt;T&gt;</code> as a parameter?</p> <p>For instance, you could have several overloads:</p> <pre><code>public override object Execute(Interpreter interpreter, IEnumerable&lt;int&gt; ctx) public override object Execute(Interpreter interpreter, IEnumerable&lt;string&gt; ctx) public override object Execute(Interpreter interpreter, IEnumerable&lt;...&gt; ctx) </code></pre> <p>Alternatively, you could re-eimplement the LINQ methods you care about to work with plain <code>IEnumerable</code>. Doing so for FirstOrDefault is relatively easy:</p> <pre><code>public static object FirstOrDefault( this IEnumerable sequence ) { if( sequence == null ) return null; using( var iter = sequence.GetEnumerator() ) { if( iter.MoveNext() ) return iter.Current; return null; } } </code></pre> <p>Re-implementing all of LINQ against IEnumerable will not be fun ... or in some cases easy. Your best bet would be to create an adapter that allows you to treat <code>IEnumerable</code> as <code>IEnumerable&lt;object&gt;</code> - then you can use it regardless of whether you're dealing with sequences of value types or reference types:</p> <pre><code>public static IEnumerable&lt;object&gt; AsObjectSequence( this IEnumerable sequence ) { foreach( object x in sequence ) yield return x; } </code></pre> <p><strong>EDIT:</strong> It turns out, this is in principle, equivalent to using:</p> <pre><code>sequence.Cast&lt;object&gt;() </code></pre> <p>so yoy may want to use that, since it's more concise and directly built into LINQ.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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