的我想過濾收集了大量的未知類型的篩選大量收集未知類型
List<object> _list;
我需要在這也傳遞運行時
List<SearchField> _searchFields;
SearchField多個屬性的值來搜索基本上有一個字符串屬性「ProprtyName」
class SearchField
{
public string PropertyName{get; set;}
}
我試過
_list.Select(localItem => (from searchField in SearchFields
let displayProperty = (from PropertyDescriptor property in properties
where property.Name.ToLower() == searchField.FieldName.ToLower()
select property).FirstOrDefault()
where displayproperty != null
let valueBinding = new BindingEvaluator<string>
(
new Binding(displayproperty.Name)
{
Mode = BindingMode.TwoWay, Source = localItem
})
let obj = valueBinding.GetDynamicValue(localItem,true) ?? string.Empty
select new IndexItem
{
SearchField = searchField,
Text = obj,
Item = localItem,
}}).ToList()))
但是會收集像20,000個物品那麼大的收集需要8秒,這是完全不可接受的。請建議我在哪裏做錯了,我該怎麼做來優化它。
反射很慢...... nuff說:)。 – Asken 2012-02-21 06:34:25
'_searchFields'和'properties'集合的大小是多少? – penartur 2012-02-21 06:36:01
大小更像20,000個項目 – gaurawerma 2012-02-21 06:38:36