Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is a sample that works and how you can force which will be called:</p> <pre><code> private static readonly Program p = new Program(); private Foo foo; static void Main(string[] args) { p.foo = new Foo(); p.foo.IsFoo = true; p.foo.IsIFoo = true; // uses Transact(Func&lt;Foo, bool&gt; funcBlock) var isFoo = p.Transact(f =&gt; f.IsFoo == true); Console.WriteLine("isFoo: {0}", isFoo); // this is ambiguous //var isIFoo = p.Transact(f=&gt; (f as IFoo).IsIFoo == true); // this works var isIFoo = p.Transact((IFoo f) =&gt; f.IsIFoo == true); Console.WriteLine("isIFoo: {0}", isIFoo); Console.ReadLine(); } bool Transact(Func&lt;Foo, bool&gt; funcBlock) { Console.WriteLine("Transact(Func&lt;Foo, bool&gt; funcBlock)"); return (funcBlock(p.foo)); } bool Transact(Func&lt;IFoo, bool&gt; funcBlock) { Console.WriteLine("Transact(Func&lt;IFoo, bool&gt; funcBlock)"); return (funcBlock(p.foo)); } } class Foo : IFoo { public bool IsFoo { get; set; } public bool IsIFoo { get; set; } } interface IFoo { bool IsIFoo { get; set; } } </code></pre> <p>As someone else stated, the compiler will determine which function is being called. But in my example, Foo is also an IFoo so I assume this is the crux of the issue.</p> <p>Output: </p> <blockquote> <p>Transact(<code>Func&lt;Foo, bool&gt; funcBlock</code>)<br> isFoo: True </p> <p>Transact(<code>Func&lt;IFoo, bool&gt; funcBlock</code>)<br> isIFoo: True</p> </blockquote> <p><strong>Update</strong> <em>per comment</em><br> To summarize and put this in scope of the question, use one of the following to determine which function your code should call:</p> <pre><code>((DbTransaction transaction) =&gt; ...) </code></pre> <p>... or</p> <pre><code>((IDbTransaction transaction) =&gt; ...) </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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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