Expression<Func<MyObject, object>>
のメソッドを呼び出して拡張したいを受け取るメソッドがありobject
ます。拡張式の結果は常にbool
. 本質的に私はに「変換」Expression<Func<MyObject, object>>
したいExpression<Func<MyObject, bool>>
。
ここに私がやりたいことの要点があります。これは、 ではなくReportExpr
のタイプのようにコンパイルされないことを認識していますが、これは意図を伝えていると思います。Expression<Func<MyObject, bool>>
MethodCallExpression
private MyObjectData CreateMyObjectData(string description,
FieldTypes fieldType, Expression<Func<MyObject, object>> expression)
{
var data= new MyObjectData()
{
ReportDesc = description,
FieldType = fieldType,
};
var method = typeof(DateTime?).GetMethod("Between");
Expression<Func<MyObject, DateTime?>> from = x => x.FromValue as DateTime?;
Expression<Func<MyObject, DateTime?>> to = x => x.ToValue as DateTime?;
var methodCallExpression = Expression.Call(expression, method, from, to);
data.ReportExpr = methodCallExpression;
return data;
}