{
...
var dbLocList = from x in _dbLocList
where x.company_id == companyid
and x的searchField==searchValue //这里要查询的字段是变量
select x;
}
and那一句怎么实现
public static class Extension
{
public static List<T> FinData<T>(this List<T> MyDataList, string CName, string CValue)
{
BindingFlags bindingFlags = BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static;
PropertyInfo[] propertyInfos = typeof(T).GetProperties(bindingFlags);
List<T> ResultList = new List<T>();
foreach (PropertyInfo propertyInfo in propertyInfos)
{
if (propertyInfo.Name == CName)
{
MyDataList.ForEach(
j =>
{
string re = propertyInfo.GetValue(j, null).ToString();
if (re == CValue)
{
ResultList.Add(j);
}
}
);
}
}
return ResultList;
}
}
上面的问题解决了:
var dbLocList =Extension.FinData(_dbLocList,searchField,searchValue);