using System; using System.Collections.Generic; using System.Linq; using System.Text; ////---------------------------------------------------------------- ////Module Name: LinqExtensions ////Purpose: ////CopyRight: Muchinfo ////History: ////---------------------------------------------------------------- ////DateTime 2015/1/20 11:19:51 ////Author ouyang.hongbin ////Description Create ////---------------------------------------------------------------- //---------------------------------------------------------------- //Module Name: LinqExtensions //Purpose: //CopyRight: Muchinfo //History: //---------------------------------------------------------------- //DateTime 2015/1/20 11:19:51 //Author ouyang.hongbin //Description Create //---------------------------------------------------------------- namespace Muchinfo.MTPClient.Data.Extensions { public static class LinqExtensions { public static IEnumerable Distinct(this IEnumerable source, Func selector) { if (source == null) { throw new ArgumentNullException("source"); } if (selector == null) { throw new ArgumentNullException("selector"); } var pdis = source.Select(t => selector(t)).Distinct(); foreach (var item in pdis) { yield return source.First(t => selector(t).Equals(item)); } } } }