是否有任何方法可以缩短对此方法的调用?似乎很长,第二个参数是否需要强类型输入?如果已知列表,是否在FindPercent上需要?
Model.FindPercent<IStatisticDisplay>(t => t.FaceoffsWon,
new Func<IStatisticDisplay, double?>[] { q => q.FaceoffsWon, q => q.FaceoffsLost }, "-")
方法
public static string FindPercent<T>(this List<T> list, Func<T, double?> numerator,
Func<T, double?>[] totals, string defValue)
{
return Helper.FindPercent(list, numerator, totals, defValue);
}
答案 0 :(得分:1)
只需使用params
并删除类型!
public static string FindPercent<T>(this List<T> list, string defValue, Func<T, double?> numerator, params Func<T, double?>[] totals)
{
return Helper.FindPercent(list, numerator, totals, defValue);
}
Model.FindPercent("-", t => t.FaceoffsWon, q => q.FaceoffsWon, q => q.FaceoffsLost );