I'm practising how to create an open-closed principle with C# to return a list of info. but the problem is I'm getting an error in my main service class.
These are my sample codes:
I have this interface:
public interface ISelectInfo{
bool Rule(string rule);
IQueryable<FoodDto> ReturnSearchResult(string query);
}
I have this class that implements this interface.
public class Fruit : ISelectInfo {
public bool Rule(string rule){
return "fruit".Equals(rule);
}
public IQueryable<FoodDto> ReturnSearchResult(string query){
// returns a list of FoodDto
}
}
And I have this main service class
public class SelectTypeOFoodService {
private readonly IList<ISelectInfo> selectInfo;
public SelectTypeOfFruitService (IList<ISelectInfo> selectInfo){
this.selectInfo = selectInfo;
}
public async IEnumerable<FoodDto> SelectFood(string rule, string query){
return await selectInfo.ToList().Where(x=>x.Rule(rule)).Select(x=>x.ReturnSearchResult(query)).AsQueryable().TolistAsync();
}
}
I'm getting an error and red squiggle line on my return await selectInfo.ToList()...
What I'm trying to achieve it to return a list of FoodDto that based from Open-closed principle.
Here's the sample result of the red squiggle line that is showing Cannot convert expression type 'System.Collections.Generic.List<System.Linq.IQueryable<FoodDto>>' to return type 'System.Collections.Generic.IEnumerable<FoodDto>'
I hope somebody can help me.