我已经安装了 Clr Heap Allocation Analyzer 扩展程序,在一个项目中我看到了一些我不太理解的东西,我有一个带有签名的方法
public Task<int> ExecuteAsync(string sql, dynamic param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null)
{
param = SetModificationValuesForGlobalRing(param);
return _sqlPolicy.ExecuteAsync(async () =>
{
int result;
using (var connection = new SqlConnection(_connectionString))
{
await connection.OpenAsync();
result = await connection.ExecuteAsync(sql, param as object, transaction, commandTimeout, commandType);
}
return result;
});
}
这个工具在方法和所有参数上给了我一个警告,说:
编译器将会生成一个类来将此作为字段持有,以允许捕获此闭包。
我不知道这种行为发生的原因,是因为可选参数吗?