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
Is the OfType(...)
method (link) what you're looking for?
public class MyModel : IModel where T : MyObjectBase
{
public IQueryable GetRecords()
{
var entities = Repository.Query();
if (typeof(IFilterable).IsAssignableFrom(typeof(T)))
{
//Filterme is a method that takes in IEnumerable
entities = FilterMe(entities));
}
return entities;
}
public IEnumerable FilterMe(IEnumerable linked) where TResult : IFilterable
{
var dict = GetDict();
return linked.OfType().Where(r => dict.ContainsKey(r.Id));
}
}