本帖最后由 wuyiqun 于 2015-01-30 14:32:39 编辑

解决方案 »

  1.   

    T在运行时,才知道实际类型
    除去反射,应该是没办法知道T是否有id属性的。
      

  2.   

    static T GetObjectPropertyValue<T>(IList<T> list, string propertyname, object propertyvalue)
            {
                Type type = typeof(T);
                foreach (T t in list)
                {
                    type = typeof(T);                PropertyInfo property = type.GetProperty(propertyname);                if (property == null) return t;                object o = property.GetValue(t, null);                if (o == null) return t;                if (propertyvalue.ToString() == o.ToString())
                        return t;
                }
                return default(T);
            }
      

  3.   

    要快需要用sortedlist,list查找使用线性查找快不起来