我有以下代码:
public void Test(Request request, Func<IEnumerable<Building>> buildings)
{
vm.Buildings = Helper.GenerateDropdownList(request.BuildingId,() => buildings());
}
我现在想要将另一个参数传递给buildings()
回调
public void Test(Request request, Func<IEnumerable<Building>> buildings)
{
var cityId = GetCity();
vm.Buildings = Helper.GenerateDropdownList(request.BuildingId,() => buildings(cityId));
}
输入该参数的正确方法是什么?
答案 0 :(得分:3)
您的buildings
代表必须是Func<T, TResult>
而不是Func<TResult>
。
假设cityId
是int
:
public void Test(Request request, Func<int, IEnumerable<Building>> buildings)
{
var cityId = GetCity();
m.Buildings = Helper.GenerateDropdownList(request.BuildingId,
() => buildings(cityId));
}