Skip to content

Instantly share code, notes, and snippets.

@hagbarddenstore
Last active August 29, 2015 14:10
Show Gist options
  • Save hagbarddenstore/5b85caa65f53fea16fc7 to your computer and use it in GitHub Desktop.
Save hagbarddenstore/5b85caa65f53fea16fc7 to your computer and use it in GitHub Desktop.
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