Note that there are some explanatory texts on larger screens.

plurals
  1. POClass type inference from static method / caller?
    primarykey
    data
    text
    <p>Given the following two classes:</p> <pre><code>public class ABC { public void Accept(Ordering&lt;User&gt; xyz) { // Do stuff with xyz... } } public class Ordering&lt;TEntity&gt; where TEntity : class { private readonly Func&lt;IQueryable&lt;TEntity&gt;, IOrderedQueryable&lt;TEntity&gt;&gt; Transform; private Ordering(Func&lt;IQueryable&lt;TEntity&gt;, IOrderedQueryable&lt;TEntity&gt;&gt; transform) { this.Transform = transform; } public static Ordering&lt;TEntity&gt; By&lt;TKey&gt;(Expression&lt;Func&lt;TEntity, TKey&gt;&gt; expression) { return new Ordering&lt;TEntity&gt;(query =&gt; query.OrderBy(expression)); } public static Ordering&lt;TEntity&gt; ByDescending&lt;TKey&gt;(Expression&lt;Func&lt;TEntity, TKey&gt;&gt; expression) { return new Ordering&lt;TEntity&gt;(query =&gt; query.OrderByDescending(expression)); } public Ordering&lt;TEntity&gt; ThenBy&lt;TKey&gt;(Expression&lt;Func&lt;TEntity, TKey&gt;&gt; expression) { return new Ordering&lt;TEntity&gt;(query =&gt; this.Transform(query).ThenBy(expression)); } public Ordering&lt;TEntity&gt; ThenByDescending&lt;TKey&gt;(Expression&lt;Func&lt;TEntity, TKey&gt;&gt; expression) { return new Ordering&lt;TEntity&gt;(query =&gt; this.Transform(query).ThenByDescending(expression)); } public IOrderedQueryable&lt;TEntity&gt; Apply(IQueryable&lt;TEntity&gt; query) { return Transform(query); } } </code></pre> <p>Used in the following way:</p> <pre><code>ABC abc = new ABC(); abc.Accept(Ordering&lt;User&gt;.By(u =&gt; u.Id)); </code></pre> <p>Is there any way to infer the type of <code>T</code> like so:</p> <pre><code>abc.Accept(Ordering.By(u =&gt; u.Id)); </code></pre>
    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.
 

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