You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When you have a CancellationToken in scope and two methods, one that takes a params array and another that takes a regular array and a CancellationToken, for example the two following methods defined in DbSet<TEntity> in Entity Framework Core:
...it favors the params method as expected if you pass an object, but the analyzer doesn't give a warning that I should use the other method with manual array construction, and pass the CancellationToken
Observed and Expected Behavior
As described above, it doesn't warn when using a method that takes a params array when there's another method that takes a regular array and a CancellationToken:
// No warning here.varserver=await dbContext.Servers.FindAsync(command.Id);// What it should tell me to do.varserver=await dbContext.Servers.FindAsync(newobject[]{ command.Id }, cancellationToken);
The analyzer should warn me that I should construct the array directly and use the 2nd overload and pass along the CancellationToken, as shown in the example above.
The text was updated successfully, but these errors were encountered:
So, this isn't a bug, it's definitely working as intended. But it's definitely a common case that should be supported.
The issue is that the proper fix is more than just adding CancellationToken to the arguments list. You have also have to wrap all the other arguments. The analyzer sees these calls as "incompatible" on account of the presence of the params keyword on only one of them.
I think it's worth creating a separate diagnostic code for this case, since the codefix is a little more involved, and requires a transform of the other arguments. Might even just not provide a codefix for this, since it would basically involve re-inventing argument binding, to figure out which arguments need transformed into the params array, and which don't.
I thought as much. It's simply something the analyzer doesn't cover at the moment, as it's a separate thing. So I guess my issue is a feature request then 😄 Is it possible to have a codefix that if it sees another overload like in my example, it will construct the array directly and pass the CancellationToken?
Version
1.0.1
Description
When you have a
CancellationToken
in scope and two methods, one that takes a params array and another that takes a regular array and aCancellationToken
, for example the two following methods defined inDbSet<TEntity>
in Entity Framework Core:...it favors the params method as expected if you pass an object, but the analyzer doesn't give a warning that I should use the other method with manual array construction, and pass the
CancellationToken
Observed and Expected Behavior
As described above, it doesn't warn when using a method that takes a params array when there's another method that takes a regular array and a
CancellationToken
:The analyzer should warn me that I should construct the array directly and use the 2nd overload and pass along the
CancellationToken
, as shown in the example above.The text was updated successfully, but these errors were encountered: