Last active
August 29, 2015 14:05
-
-
Save urasandesu/3ac9843b2f457579e6d4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
using System; | |
namespace ConsoleApplication | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var interceptor = default(Func<Func<DateTime>, Func<DateTime>>); | |
interceptor = indirection => () => | |
{ | |
try | |
{ | |
Console.WriteLine("前処理"); | |
return indirection(); | |
} | |
finally | |
{ | |
Console.WriteLine("後処理"); | |
} | |
}; | |
var intercepted = interceptor(() => { Console.WriteLine("本処理"); return DateTime.Now; }); | |
Console.WriteLine("結果: {0}", intercepted()); | |
// -------------------------- | |
// 前処理 | |
// 本処理 | |
// 後処理 | |
// 結果: 2014/08/15 16:09:12 | |
Console.ReadLine(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment