扩展类
public static class Extensions { //2016.1.18 start public static int toInt(this string str) { return Convert.ToInt32(str); } public static bool IsNullOrEmpty(this string s) { return string.IsNullOrEmpty(s); } } }
2016.2.26
增加泛型去重复
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ssm.Helper { public static class Extensions { //2016.1.18 start public static int toInt(this string str) { return Convert.ToInt32(str); } public static bool IsNullOrEmpty(this string s) { return string.IsNullOrEmpty(s); } public static IEnumerable<TSource> DistinctBy<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector) { HashSet<TKey> seenKeys = new HashSet<TKey>(); foreach (TSource element in source) { if (seenKeys.Add(keySelector(element))) { yield return element; } } } } }