【发布时间】:2011-04-02 11:23:51
【问题描述】:
我想使用 lambda 将匿名属性传递给泛型函数并在那里访问它。
以及如何访问里面的属性。
using (CommentsRepository commentsRepository = new CommentsRepository())
{
var comments = commentsRepository.GetAllComments();
Foo<Comment>(comments, 0,com=>com.ID); //Comment is an EF entity
}
public static void Foo<TObject>(IEnumerable<TObject> list, int iCurID, <Func<TObject, TProperty> property) where TObject : class
{
foreach (var cat in list.Where(/*How to access the property*/==iCurID)
{
int x = cat.property;
}
}
【问题讨论】:
标签: c# entity-framework generics lambda