我有以下代码:
queryProjects = queryProjects
.Where(a => a.Field<int>("ProjectType") == projectType
&& a.Field<string>("Descr")
.IndexOf(@str, StringComparison.OrdinalIgnoreCase) >= 0
|| a.Field<string>("ProjectId")
.IndexOf(@str, StringComparison.OrdinalIgnoreCase) >= 0
|| a.Field<string>("LastChangedBy")
.IndexOf(@str, StringComparison.OrdinalIgnoreCase) >= 0
);
如何使问号所在的a.Field< ??? >
数据类型动态化?
答案 0 :(得分:0)
在您的字段属性所在的类型上,重新定义它,如下所示:
public T Field<T>(string key)
{
object field = null; // Get your field value here
return (T)field;
}