I have several classes that implement a specific interface (ISearchable), and I would like to return an IEnumerable of the base type (ISearchable) from the static method, but I'm not sure how to convert it without intermediate collections.
The code is pretty simple, one of the implementations of domain objects is this:
public class account : ISearchable
{
public static IEnumerable<ISearchable> Search(string keyword)
{
ORMVendorCollection<account> results =
return results.AsEnumerable<account>();
return results.AsEnumerable<ISearchable>();
}
}
Client code, ideally, looks like this:
public static IEnumerable<ISearchable> Search(string keyword)
{
return account.Search(keyword)
.Concat<ISearchable>(order.Search(keyword))
.Concat<ISearchable>(otherDomainClass.Search(keyword));
}
source
share