【发布时间】:2013-12-31 04:56:35
【问题描述】:
我有checkedlistbox 使用我的通用列表绑定。我需要根据价值检查项目。当我使用对象集合绑定时,我需要转换对象并检查 id。为此,我使用了以下循环,并且成功了
if (currentDeliveryNote.Quotations != null)
{
foreach (QuotationBase item in currentDeliveryNote.Quotations)
{
for (int i = 0; i < chklstQuotation.Items.Count; i++)
{
if (((QuotationBase)chklstQuotation.Items[i]).ID == item.ID)
{
chklstQuotation.SetItemChecked(i, true);
}
}
}
}
现在同样的概念也适用于所有其他页面。但唯一的区别是对象名称不同。例如:在此页面中,这是QuotationBase。对于下一页,这是DeliveryNote,另一个是Invoice等。
那么我如何编写通用扩展方法来检查项目。所有对象都有 ID 属性,用于与列表进行比较以进行检查。
【问题讨论】:
-
你有没有 Quotationbase、DeveliveryNote 和 Invoice 的基类以及 ID 的类型。
标签: c# extension-methods generic-list generic-collections