Guest User

Untitled

a guest
Apr 25th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace TestPipelineC
  5. {
  6. public delegate T Del<T>(T item);
  7.  
  8. internal class Program
  9. {
  10. private static void Main(string[] args)
  11. {
  12. string h = "hello friends";
  13. string r = h.Pipe(Mangle);
  14. object r2 = h.Pipe(Mangle);
  15. int i = 17;
  16. int j = i.Pipe(OtherMangle);
  17. List<int> l = new List<int>();
  18. l.Add(1);
  19. l.Add(2);
  20. l.Add(3);
  21. List<int> l2 = l.Pipe(Mangle3);
  22.  
  23. Console.WriteLine(r);
  24. Console.WriteLine(r2);
  25. Console.WriteLine(i);
  26. Console.WriteLine(j);
  27. foreach (var s in l2)
  28. {
  29. Console.WriteLine(s);
  30. }
  31.  
  32. }
  33.  
  34.  
  35. public static string Mangle(string s)
  36. {
  37. return s.ToUpper();
  38. }
  39.  
  40. public static int OtherMangle(int i)
  41. {
  42. return i*i;
  43. }
  44.  
  45. public static List<int> Mangle3(List<int> l)
  46. {
  47. var l2 = new List<int>();
  48.  
  49. foreach (var i in l)
  50. {
  51. l2.Add(i*3);
  52. }
  53. return l2;
  54. }
  55.  
  56. }
  57.  
  58.  
  59. internal static class Awesome
  60. {
  61. public static T Pipe<T>(this T o, Del<T> a)
  62. {
  63. return (T) a.DynamicInvoke(o);
  64. }
  65. }
  66. }
Add Comment
Please, Sign In to add comment