Params For Func constituent or what?
-
We need a list with Functions. Implementation of the Statutory Species Lista, where functions are performed with only static 1 parameter, e.g. type int I could. The next question? How can it be realized that the functions of any type of parameter and in a non-static number can be incorporated into the leaflet and can they be done?
For example, it is possible to place 3 functions of such species in 1 List.
async Task<string> testTask() {} async Task<string> testTask(int a) {} async Task<string> testTask(string a, object b) {}
That's the only thing I could think of, but, alas, it obviously doesn't work.
List< Func< params(object),Task< string>>> _list;
-
First, we need to answer the question - how will you be with an unknown number of parameters in advance? The answer to this question and the method of storage. It is possible to convert the function to the right type through the lock.
Examples.
var list = new List<Func<Task<string>>>(); list.Add(testFunc); list.Add(() => testFunc(5)); list.Add(() => testFunc("6", "Hello, world!"));
var list = new List<Delegate>();
list.Add(new Func<Task<string>>(testFunc));
list.Add(new Func<int, Task<string>>(testFunc));
list.Add(new Func<string, string , Task<string>>(testFunc));var list = new List<Func<object[], Task<string>>>();
list.Add(a => testFunc());
list.Add(a => testFunc((int)a[0]));
list.Add(a => testFunc((string)a[0], (string)a[1]));