*CoreAsync vs *Async #2239
Comments
The short answer is: The For some more background: We started with public void SendAsync(string method, object[] args);
Clients.All.SendAsync("Method", new object[] { arg1, arg2, arg3 }); Obviously it's a pain to have to create an array every time. The easy fix for that would be to use public void SendAsync(string method, params object[] args);
Clients.All.SendAsync("Method", arg1, arg2, arg3); However, that falls apart when you actually want to send an array as a single argument public void SendAsync(string method, params object[] args);
var arg1 = new object[] { a, b, c };
Clients.All.SendAsync("Method", arg1);
// C# 'params' expands this into the below
Clients.All.SendAsync("Method", a, b, c); So instead of sending a single argument that is an array So we removed the
But there's still ambiguity when you have code like this: public void SendAsync(string method, object[] args);
public void SendAsync(string method, object arg1) => SendAsync(method, new object[] { arg1 });
var arg = new object[] { a, b, c }
Clients.All.SendAsync("method", arg); Again, the overload that takes an So, we renamed the one that takes an array to public void SendCoreAsync(string method, object[] args);
public void SendAsync(string method, object arg1) => SendCoreAsync(method, new object[] { arg1 });
var arg = new object[] { a, b, c }
// No ambiguity here!
Clients.All.SendAsync("method", arg); We will have XML docs that show up in IntelliSense in the RTM to help explain this. |
Thank you for explanation. |
@anurse I'm currently sending a single list of objects using SendAsync. That extension methods aren't supported by some mocking frameworks. I can't use SendCoreAsync either for the reasons above. Are there near-term plans to make these extension methods instance methods or will I need to abstract these calls out to a wrapper class of some kind? |
The extension methods all just call |
You're, right. At one point I tried that and it failed but later found it was due to something unrelated. Thanks for the response. |
Explanation makes sense. As a sidenote, I was initially drawn to the "SendCore" because "Core" could refer to a .Net "Core" feature which is a common pattern especially in NuGet naming (e.g. "EntityFrameworkCore"). |
@myrup This generally isn't the case in method names, but that's a good point to make. |
I've noticed 2.1 introduced new methods with
core
infix. ComparingSendCoreAsync
andSendAsync
, is there any specific difference between the two of them other thanSendCoreAsync
not being an extension (beside array of arguments as a parameter)? Which one should we use?The text was updated successfully, but these errors were encountered: