■ C# 10.0 での新機能
・ラムダの機能強化 ラムダ属性 (Lambda improvements)
https://docs.microsoft.com/ja-jp/dotnet/csharp/language-reference/operators/lambda-expressions#attributes
ラムダで属性が使える、また return 値の型も書ける。メソッドの引数などでラムダを渡したいときの扱いの改善。
MapAction([HttpPost("/")] ([FromBody] string todo) => todo); // ラムダで属性が使える MapAction(string (todo) => todo); // 直接各ラムダで return の型ががける //MapAction([HttpPost("/")] todo => todo); // これはエラー。ラムダに属性をつける場合、引数リストは ( ) が必要 MapAction([HttpPost("/")] (todo) => todo); // これは ( ) があるので OK // 関数やクラスの定義 // Function void MapAction(Func<string, string> action) {; } // 属性 class HttpPostAttribute : Attribute { public HttpPostAttribute(string root) {; } } class FromBodyAttribute : Attribute { public FromBodyAttribute() {; } }