Suppose I have a base class and inherited class
public class BaseClass
{
public String SystemName { get; set; }
public String UserName { get; set; }
}
internal class InheritedClass : BaseClass
{
public Guid Id { get; set; }
}
Some expression over base class is passed to my module from outside (inherited class is not visible from there)
Expression<Func<BaseClass, bool>>
It describes some filtering logic, for example like that
Expression<Func<BaseClass, bool>> filter = x => x.SystemName.StartsWith("ABC") && x.UserName != ""
But inside my module I need to use
Expression<Func<InheritedClass, bool>>
Because I apply this filter to IQueryable, like that
IQueryable<InheritedClass> filteredItems = Items.Where(filter);
Inherited class has all properties of base class - so my not-so-experienced mind suppose convertation is possible :)
Is there any way to convert passed expression to what I need?
Thank you.