8

我有 :

 public void InitializeStatusList(DropDownList list)
    {
       var dictionaryEntries = GetEntriesFromDatabase();
       list.DataSource = dictionaryEntries.Where(entry => entry is EntryStatus1 || entry is EntryStatus2);
       list.DataBind();           
    }

我有很多这样的功能。我想编写dictionaryEntries查询条件作为谓词传递的通用函数。

例如:

public void InitializeStatusList(DropDownList list)
{
    CommonInitializeStatusList(DropDownList list, entry => entry is EntryStatus1 || entry is EntryStatus2);
}

public void CommonInitializeStatusList(DropDownList list, ??????????????? predicate)
{                       
    var dictionaryEntries = GetEntriesFromDatabase();
    list.DataSource = dictionaryEntries.Where(predicate);
    list.DataBind();        
}

代表什么???????????????

提前致谢

4

2 回答 2

15

Func<Entry, bool> predicate应该工作,变量Entry的类型在哪里。entry

于 2012-05-10T09:01:54.500 回答
8

你可以这样做:

public void InitializeStatusList(DropDownList list)
{    
    Func<Entry,bool> predicate=entry=>entry is EntryStatus1 || entry is EntryStatus2;
    CommonInitializeStatusList(list, predicate);
}

public void CommonInitializeStatusList(DropDownList list, Func<Entry,bool> predicate)
{                                 
    var dictionaryEntries = GetEntriesFromDatabase();    
    list.DataSource = dictionaryEntries.Where(predicate);
    list.DataBind();

}
于 2012-05-10T09:26:30.743 回答