I have a couple of classes
Square : Rectangle : Shape (abstract)
and I have a base controller inheriting from ApiController that I would like to use.
public abstract class BaseController<T> : ApiController where T : class { public abstract IEnumerable<T> Get() ... }
and
public class DerivedController : BaseController<Rectangle> { public override IEnumerable<Rectangle> Get() ... } public class AnotherDerivedController : BaseController<Square> { public new IEnumerable<Square> Get() ... }
/ api / rectangle will correctly call IEnumerable<Rectangle> Get()
/ api / square will give me an error:
Multiple actions were found that match the request: System.Linq.IEnumerable`1[Square] Get() on type Web.Api.Controllers.AnotherDerivedController System.Linq.IEnumerable`1[Rectangle] Get() on type Web.Api.Controllers.DerivedController
If I change public new IEnumerable<Square> Get() to public override IEnumerable<Square> Get() , I get a compile-time error as the reverse signatures differ
How do I get the code to call the appropriate method? Is it necessary to explicitly register each class of methods in RegisterRoutes?
khaihon
source share