If EntityFilter<T>
could be derived from an interface and that interface had a covariant generic parameter, you could do what you are asking without generics in the method.
Notice the "out" keyword in the IEntityFilter<out T>
definition.
public class Program
{
static void Main(string[] args)
{
var ef = new EntityFilter<TestEntity>();
DoSomething(ef);
}
public static void DoSomething(IEntityFilter<IEntity> someEntityFilter)
{
}
}
public interface IEntityFilter<out T>
{ }
public class EntityFilter<T> : IEntityFilter<T>
{ }
public interface IEntity
{ }
public class TestEntity : IEntity
{ }