Last active
August 29, 2015 14:10
-
-
Save hagbarddenstore/5b85caa65f53fea16fc7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void Main() | |
{ | |
var a = Bind(new Dog(), x => x.Hello()); | |
a(); | |
var b = Bind<Dog, int>(new Dog(), (x, arg1) => x.Eat(arg1)); | |
b(3); | |
} | |
Action Bind<T>(T model, Action<T> action) | |
{ | |
return () => | |
{ | |
action(model); | |
}; | |
} | |
Action<TArg1> Bind<TModel, TArg1>(TModel model, Action<TModel, TArg1> action) | |
{ | |
return (TArg1 arg1) => | |
{ | |
action(model, arg1); | |
}; | |
} | |
class Dog | |
{ | |
public void Hello() | |
{ | |
Console.WriteLine("Woof woof"); | |
} | |
public void Eat(int amount) | |
{ | |
Console.WriteLine(string.Join(" ", Enumerable.Range(0, amount).Select(x => "Nom"))); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment