| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- 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<TSource> Distinct<TSource, TProperty>(this IEnumerable<TSource> source, Func<TSource, TProperty> 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));
- }
- }
- }
- }
|