Pro_Unit

MethodExtention_LogCollection

Feb 28th, 2019
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.61 KB | None | 0 0
  1. public static string Log<T> (this IEnumerable<T> collection) => Log (collection, i => i);
  2.  
  3. public static string Log<T, TResult> (this IEnumerable<T> collection, System.Func<T, TResult> selector, string Format = "{0}", string separator = "\n")
  4. {
  5.     string result = "";
  6.     result = collection != null ? collection.Count ().ToString () : "Null";
  7.     result += " items {0}\n------\n".AsFormat (typeof (T).Name)
  8.     foreach (var item in collection.Select (selector))
  9.     {
  10.         var parameters = new object[] { item };
  11.         result += string.Format (Format + separator, parameters);
  12.     }
  13.     return result;
  14. }
Advertisement
Add Comment
Please, Sign In to add comment