Skip to content

Instantly share code, notes, and snippets.

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