Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace TestPipelineC
- {
- public delegate T Del<T>(T item);
- internal class Program
- {
- private static void Main(string[] args)
- {
- string h = "hello friends";
- string r = h.Pipe(Mangle);
- object r2 = h.Pipe(Mangle);
- int i = 17;
- int j = i.Pipe(OtherMangle);
- List<int> l = new List<int>();
- l.Add(1);
- l.Add(2);
- l.Add(3);
- List<int> l2 = l.Pipe(Mangle3);
- Console.WriteLine(r);
- Console.WriteLine(r2);
- Console.WriteLine(i);
- Console.WriteLine(j);
- foreach (var s in l2)
- {
- Console.WriteLine(s);
- }
- }
- public static string Mangle(string s)
- {
- return s.ToUpper();
- }
- public static int OtherMangle(int i)
- {
- return i*i;
- }
- public static List<int> Mangle3(List<int> l)
- {
- var l2 = new List<int>();
- foreach (var i in l)
- {
- l2.Add(i*3);
- }
- return l2;
- }
- }
- internal static class Awesome
- {
- public static T Pipe<T>(this T o, Del<T> a)
- {
- return (T) a.DynamicInvoke(o);
- }
- }
- }
Add Comment
Please, Sign In to add comment