This is the signature for the Ok()
method in ApiController
:
protected internal virtual OkResult Ok();
And this is my method from my RestController
class (which extends from ApiController
):
// Note that I'm not overriding base method
protected IHttpActionResult Ok(string message = null);
Since OkResult
implements IHttpActionResult
, both of these methods can be called like this:
IHttpActionResult result = Ok();
In fact, that's what I'm doing in my application.
My class PersistenceRestController
(which extends from RestController
), has these lines of code:
protected override async Task<IHttpActionResult> Delete(Key id)
{
bool deleted = //... Attempts to delete entity
if(deleted) return Ok();
else return NotFound();
}
This compiles fine, and no warning is raised about method ambiguity. Why is that?
PersistenceRestController
has also inherited the protected methods from ApiController
so it should have both versions of Ok()
(and it does).
At execution, the method executed is the one from my RestController
.
How does the compiler know which method to run?