Skip to content

Instantly share code, notes, and snippets.

@einarwh
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save einarwh/757fe9df419ef4a6225d to your computer and use it in GitHub Desktop.
Save einarwh/757fe9df419ef4a6225d to your computer and use it in GitHub Desktop.
static void Main (string[] args)
{
Func<Func<string>, Func<string>> wrap = fn => fn
.Before(() => Console.WriteLine("I'm happening early on."))
.Success(r => Console.WriteLine("Successfully obtained: " + r))
.Before(() => Console.WriteLine("When do I occur???"))
.After(r => Console.WriteLine("What did I get? " + r));
var m1 = wrap(() => {
Console.WriteLine("Executing m1...");
return "Hello Kiczales!";
});
var m2 = wrap(() => {
Console.WriteLine("Executing m2...");
throw new Exception("Boom");
});
Call("m1", m1);
Call("m2", m2);
}
static void Call(string name, Func<string> m) {
Console.WriteLine(name);
try {
Console.WriteLine(name + " returned: " + m());
}
catch (Exception ex) {
Console.WriteLine("Exception in {0}: {1}", name, ex.Message);
}
Console.WriteLine();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment