0
我有这样的方法:变换私人判断方法,以异步方式
/// <summary>
/// Gets the query filter.
/// </summary>
/// <param name="queryText">The query text.</param>
/// <returns>The query filter predicate.</returns>
private Task<Predicate<int>> GetQueryFilter(string queryText)
{
// Return the query filter predicate
return new Predicate<int>(async(id) =>
{
// Get the employee
StructuredEmployee employee = await LoadEmployee(id);
// If employee not found - return false
if (employee == null)
return false;
// Else if employee is found
else
// Check subject and body
return (!string.IsNullOrWhiteSpace(employee.FirstName)) && employee.FirstName.Contains(queryText)
|| (!string.IsNullOrWhiteSpace(employee.MiddleName)) && employee.MiddleName.Contains(queryText)
|| (!string.IsNullOrWhiteSpace(employee.LastName)) && employee.LastName.Contains(queryText);
});
}
我想这个方法来异步返回,即Task<Predicate<int>>
。 我该如何去做这件事? 目前,我在async(id)
上有编辑错误。
这只是返回一个谓词 - 你确定它是你想异步运行的GetQueryFilter方法,而不是谓词本身?如果你想要一个异步谓词,那是另一回事。如果你能在这里解释最终目的,那真的很有帮助。 – 2013-05-08 20:51:11