日期:2014-05-20 浏览次数:20778 次
public IList<T> FilterRepeat<T>(IList<T> t, string attName) { if (t.Count <= 0) return t; #region 查找attName所在的位置 int index = -1; for (int i = 0; i < t[0].GetType().GetProperties().Count(); i++) { if (t[0].GetType().GetProperties()[i].Name == attName) { index = i; break; } } #endregion if (index == -1) return t; IList<T> result = new List<T>(); var sr = from s in t group s by s.GetType().GetProperties()[index].GetValue(s, null); foreach (var group in sr) result.Add(group.ToList()[0]); return result; }