123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Linq.Expressions;
- using System.Text;
- namespace DymWebForm.Common.Linq
- {
- internal static class Extensions
- {
- public static T2[] SelectArray<T1, T2>(this IEnumerable<T1> source, Func<T1, T2> selector)
- {
- return source.Select(selector).ToArray();
- }
- public static T2[] SelectArray<T1, T2>(this IQueryable<T1> source, Expression<Func<T1, T2>> selector)
- {
- return source.Select(selector).ToArray();
- }
- public static T2 FirstValue<T1, T2>(this Dictionary<T1, T2> source)
- {
- foreach (var item in source)
- {
- return item.Value;
- }
- throw new InvalidOperationException("No items in dic");
- }
- public static IEnumerable<T> ForEach<T>(this IEnumerable<T> source, Action<T> proc)
- {
- var arr = source as T[] ?? source.ToArray();
- foreach (var item in arr)
- proc(item);
- return arr;
- }
- public static IEnumerable<T> ForEach<T>(this IQueryable<T> source, Action<T> proc)
- {
- foreach (var item in source)
- proc(item);
- return source;
- }
- }
- }
|