Reputation: 2609
I have code like this:
private Func<Request, Response, byte[], string, string, Task> _started;
private Func<Request, Response, byte[], string, string, Task> _progress;
private Func<Request, Response, byte[], string, string, Task> _completed;
private Func<Request, Response, byte[], string, string, Task> _errorOccurred;
private Func<Request, Response, byte[], string, string, Task> _cancelled;
I'd better have something like:
typedef Func<Request, Response, byte[], string, string, Task> StatusUpdateAsyncCallback; // in C++ way.
private StatusUpdateAsyncCallback _started;
// and so on.
Can't figure out how to do this with Func. I'm used to delegates (where I didn't have this problem as I can give a unique name to any delegate) but now can't figure out how to repeat the same for Func declarations.
I'm migrating from simple declaration of a delegate type like delegate Task StatusUpdateAsyncCallback(Request req, Response resp, byte[] data, string account, string alias)
because I'll now rely on some Func-specific abilities (for instance, it's possible to make an extension method which will work for all kinds of Func delegates with certain number of parameters while 'classic' delegates types are not compatible in this way). If more info needed on this, can be found in @Mant101 explanations at How to write extension method which will make invocation list members in multicast C# delegate run sequentially?
Upvotes: 1
Views: 163
Reputation: 12201
You can use using
(in every file):
using StatusUpdateAsyncCallback =
System.Func<Request, Response, byte[], string, string, System.Threading.Tasks.Task>;
All type names should be fully-qualified.
Upvotes: 5
Reputation: 2609
At least for the same source file, this will work:
using StatusUpdateAsyncCallback = System.Func<Request, Response, byte[], string, string, System.Threading.Tasks.Task>;
The key point is to always provide full type names in using directive (System.Func
, System.Threading.Tasks.Task
). Earlier using System.Threading.Tasks
and using System
declarations have no effect.
Upvotes: 0
Reputation: 203820
You can create a type alias using using
, although it's only going to apply within that file, not the rest of the assembly.
using StatusUpdateAsyncCallback =
System.Func<Request, Response, byte[], string, string, System.Threading.Tasks.Task>;
Upvotes: 2