在这里解释我的问题一个简短的例子:
public interface IData
{
Guid Id { get; }
DateTime Time { get; }
}
public interface IProvider
{
IEnumerable<IData> GetObjects(Expression<Func<IData,bool>> expr);
}
public class MyData : IData { ... }
public class MyProvider : IProvider
{
IEnumerable<IData> GetObjects(Expression<Func<IData,bool>> expr)
{
// !!! This part is my problem:
// I need to convert the Expression, defined on the Interface
// to the actual implemented class.
return GetObjectsSpecific(expr); // Does not work!!!
}
IEnumerable<MyData> GetObjectsSpecific(Expression<Func<MyData,bool>> expr)
{
// Already fully implemented und functional
}
}
public class Program
{
public void Test()
{
IProvider prov = new MyProvider();
var objects = prov.GetObjects(data => data.Time < DateTime.Now);
}
}
所以问题是:在公共接口上定义的表达式是否可以转换(?),以便它使用实际的类来实现公共接口?
有什么想法吗?