質問を表現するより良い方法は考えられませんでしたが、私がやろうとしているのは、LambdaExpression が評価される前にのインスタンスを処理することによってExpression<Func<MyObject, FilterObject, bool>>
、LambdaExpression の署名を から に減らすことです。Expression<Func<MyObject, bool>>
FilterObject
簡単な例を次に示します。
AddFilter("Filter Name", FilterTypes.All,
(x, y) => GetConjunctionResult(
x.PersonA.IsSomething, x.PersonB.IsSomething, y.ConjunctionType));
private static bool GetConjunctionResult(bool personA, bool personB,
ConjunctionType conjunctionType)
{
switch (conjunctionType)
{
case ConjunctionType.Both:
return personA && personB:
case ConjunctionType.Either:
return personA && personB;
case ConjunctionType.PersonA:
return personA;
case ConjunctionType.PersonB:
return personB;
case ConjunctionType.Neither:
return !personA && !personB;
}
}
したがって、このオーバーロードでAddFilter
型のオブジェクトを作成FilterObject
し、次の行に沿って LambdaExpression に埋め込む必要があります。
var filter = new FilterObject();
// create Expression<Func<MyObject, bool>> lambda = x => GetConjunctionResult(
// x.PersonA.IsSomething, x.PersonB.IsSomething, filter.ConjunctionType));
これを行うためのより良い方法があるかもしれないので、このアプローチを完全に回避する提案を受け入れます.