In C#, I have a function that passes in T
using generics
and I want to run a check to see if T
is an object
that implements a
public IEnumerable FilterMe(IEnumerable linked) where TResult : IFilterable
{
var dict = GetDict();
return linked.Where(r => dict.ContainsKey(r.Id));
}
Try replacing FilterMe with this version:
public IEnumerable FilterMe(IEnumerable linked)
{
var dict = GetDict();
return linked.Where(r => dict.ContainsKey(r.Id)).Cast();
}
Then, were you call, change your code to this:
if (typeof(IFilterable).IsAssignableFrom(typeof(T)))
{
//Filterme is a method that takes in IEnumerable
var filterable = entities.Cast();
entities = FilterMe(entities).AsQueryable();
}