Last active
August 29, 2015 14:03
-
-
Save einarwh/757fe9df419ef4a6225d 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
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