【发布时间】:2021-04-17 23:43:27
【问题描述】:
C#中如何获取Func<>Lambda的传递参数的值
IEnumerable<AccountSummary> _data = await accountRepo.GetAsync();
string _query = "1011";
Accounts = _data.Filter(p => p.AccountNumber == _query);
这是我的扩展方法
public static ObservableCollection<T> Filter<T>(this IEnumerable<T> collection, Func<T, bool> predicate)
{
string _target = predicate.Target.ToString();
// i want to get the value of query here.. , i expect "1011"
throw new NotImplementedException();
}
我想在分配给 _target
的过滤器扩展方法中获取 query 的值【问题讨论】:
-
您必须使用
Expression<Func<T,bool>>来获取该信息。 -
好的..我正在尝试,但我不知道从哪里得到它..也许在
predicate.Body....Right的某个地方@