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