I want to implement the methods in interface using generics. But I am getting error. e.g. //Filter is a class here.
public interface IComponent<T>
{
List<T> GetOrderSummary(Filter input);
T GetOrderDetails(string orderId);
List<T> GetOrderSummaryDetails(Filter input);
}
// ORDER A AND ORDER B ARE TWO MODEL CLASSES HERE
public class OrderDetails : IComponent<OrderA>,IComponent<OrderB>
{
public List<OrderA> GetOrderSummary(Filter input)
{
//Some logic
//lst of type OrderA
return lst;
}
public List<OrderB> GetOrderSummaryDetails(Filter input)
{
//Some logic
//lst of type OrderB
return lst
}
public OrderA GetOrderDetails(string orderId)
{
throw new NotImplementedException();
}
}
I am getting error building that
OrderDetails does not implement interface member IComponent.GetOrderSummaryDetails(Filter).OrderDetails.GetOrderSummaryDetails cannot implement IComponent.GetOrderSummaryDetails(Filter) beacuse it does not have the matching return type of
List<OrderA>OrderDetails does not implement interface member IComponent.GetOrderSummary(Filter).OrderDetails.GetOrderSummary cannot implement IComponent.GetOrderSummary(Filter) beacuse it does not have the matching return type of
List<OrderB>OrderDetails does not implement interface member IComponent.GetOrderDetails(string).OrderDetails.GetOrderDetails(string) cannot implement IComponent.GetOrderDetails(string) beacause it does not have the matching return type OrderB
Please let me know how to fix these issues.
OrderDetailsclass contain 3 methods only? Please note that you cannot implement these two interfaces implicitly because then you would have two methods that have the same parameters but different return value types which is illegal in c#. You can implement them explicitly though.