Note that there are some explanatory texts on larger screens.

plurals
  1. POOverloading method's delegate parameter with an interface version
    primarykey
    data
    text
    <p>Interesting problem here. I have a class that deals with System.Data elements that was original written to use concrete classes as parameters. It was recently updated to use interfaces instead so that we had greater compatibility with other databases.</p> <p>My problem comes from the following method, and its updated counterpart:</p> <p>Old:</p> <pre><code>public bool Transact(Func&lt;DbTransaction, bool&gt; functionBlock) { ... Stuff ... } </code></pre> <p>New:</p> <pre><code>public bool NewTransact(Func&lt;IDbTransaction, bool&gt; functionBlock) { ... Stuff ... } </code></pre> <p>The old version results in a <code>DbTransaction</code> object being spit out that we can send to other methods in our projects, while the newer one gives back an <code>IDbTransaction</code>. I named the updated version <strong>NewTransaction</strong> so that the older projects out there will not be broken should the end up sitting alongside the newer library (DLL Hell and whatnot).</p> <p>I can make rename <strong>NewTransact</strong> to <strong>Transact</strong> and it will compile just fine, but I don't see a way to call one over the other. My current solution will work just fine, but eventually <strong>NewTransact</strong> will no longer be "new". At that time, removing the old method and changing the name on the new one will just cause the problem to show up again.</p> <p><strong>My question is:</strong> Is there a way to pick which specific method is called if they're both the same name?</p> <p>I'm guessing there isn't, but I figured this would make a good question.</p> <p><strong>EDIT:</strong> The key component to this question is maintaining backwards compatibility. Any answer that would require updating old software to continue to function is irrelevant. If I wanted to go back and update other projects I would simply do that in the first place rather than creating these overloads.</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.
 

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