私は次のコードを持っています:
private int AllFeb(Forecast f, IRepository repository)
{
return All(f, repository, f.Feb);
}
private int AllJan(Forecast f, IRepository repository)
{
return All(f, repository, f.Jan);
}
private int All(Forecast f, IRepository repository, int callBk)
{
var otherForecasts = repository.Query<Forecast>().Where(r => r.PersonId == f.PersonId);
if (otherForecasts.Any())
{
return otherForecasts.Sum(r => r.Feb) + callBk;
}
return 0;
}
ご覧のとおり、毎月再利用できる共有機能を考えています。問題は、All
メソッドに次の行が必要なことです。
otherForecasts.Sum(r => r.Feb)
ジェネリックである必要がありますが、Sum
メソッド内のコールバックを外部から渡す必要があります(としてハードコーディングされたくないため)r.Feb
。
ここでコードの重複を回避する方法はありますか?