In class/Microsoft.Build.Tasks/Microsoft.Build.Tasks:
[mcs.git] / tests / gtest-anon-33.cs
blob230611d002ffb03a89ff585a72087c5bb715c03a
1 using System;
2 using System.Collections.Generic;
3 using System.Text;
5 public static class IEnumerableRocks
8 public static string Implode<TSource, TResult> (this IEnumerable<TSource> self, string separator, Func<TSource, TResult> selector)
10 return Implode (self, separator, (b, e) => { b.Append (selector (e).ToString ()); });
13 public static string Implode<TSource> (this IEnumerable<TSource> self, string separator, Action<StringBuilder, TSource> appender)
15 var coll = self as ICollection<TSource>;
16 if (coll != null && coll.Count == 0)
17 return string.Empty;
19 bool needSep = false;
20 var s = new StringBuilder ();
22 foreach (var element in self) {
23 if (needSep && separator != null)
24 s.Append (separator);
26 appender (s, element);
27 needSep = true;
30 return s.ToString ();
34 class Test
36 public static void Main ()
38 Console.WriteLine (new [] { "foo", "bar" }.Implode (", ", e => "'" + e + "'"));