パラメーターとして渡したい式がメソッド本体で宣言された参照変数を参照している場合、JetBrains Rider では汎用デリゲートパラメーターを導入し、呼び出し元からラムダ式を渡すことで、これらの変数を「enlambda」できます。 以下の例では、 "The current time is: " + currentTme 式のリファクタリングを呼び出します。
static void PrintCurrentTime()
{
var currentTme = DateTime.Now.ToString("h:mm:ss tt");
Console.WriteLine("The current time is: " + currentTme);
}
private void Test1()
{
PrintCurrentTime();
}
static void PrintCurrentTime(Func<string, string> output)
{
var currentTme = DateTime.Now.ToString("h:mm:ss tt");
Console.WriteLine(output(currentTme));
}
private void Test1()
{
PrintCurrentTime(currentTme => "The current time is: " + currentTme);
}