Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

interfaces as parameters of a function [duplicate]

Tags:

c#

interface

I have an issue, hope someone can help me a bit. I have the following interface :

public interface ITaskService
{
    ITaskBase GetTask(IRequestBase request);
}

i want to implement the method something like this :

public ITaskBase GetTask(Request request) 
{

}

Where the request is a model that looks like this :

public class Request:IRequestBase
{
    public DateTime CheckIn { get; set; }

    public DateTime CheckOut { get; set; }
}

I'm getting a compilation error that says the class does not implement the interface ITaskService , but I don't get it why the request parameter is inherited from the IRequestBase interface

like image 785
Alejandro De los santos Avatar asked May 23 '26 10:05

Alejandro De los santos


1 Answers

Make ITaskService generic.

public interface ITaskService<T> where T : IRequestBase
{
    ITaskBase GetTask(T request);
}
like image 87
Daniel A. White Avatar answered May 24 '26 22:05

Daniel A. White



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!