-
Notifications
You must be signed in to change notification settings - Fork 0
/
AsyncCommand.cs
58 lines (49 loc) · 1.5 KB
/
AsyncCommand.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using System;
using System.Threading.Tasks;
using Xamarin.Forms;
namespace AsC.Helpers
{
//Pra subir
public class AsyncCommand : Command
{
public AsyncCommand(Func<Task> execute, bool CanExecute) : base(() => execute(), () => CanExecute)
{
}
public AsyncCommand(Func<Task> execute) : base(() => execute())
{
}
public AsyncCommand(Func<Task> execute, Func<bool> canExecute) : base(() => execute(), () => canExecute())
{
}
public AsyncCommand(Func<object, Task> execute, Func<object, bool> canExecute)
: base((o) => execute(o), (o) => canExecute(o))
{
}
public AsyncCommand(Func<object, Task> execute)
: base(o => execute(o))
{
}
//public async void Execute(object args)
//{
// var t = Task.Run(()=> base.Execute(args));
// await t;
//}
}
public sealed class AsyncCommand<T> : Command
{
public AsyncCommand(Func<T, Task> execute, Func<object, bool> canExecute)
: base(async a => await execute((T)a), (a) => canExecute(a))
{
}
public AsyncCommand(Func<T, Task> execute, bool canExecute)
: base(async o => await execute((T)o), (o) => canExecute)
{
}
//public Task MyExecute(object args)
//{
// Task.Run(() => base.Execute(args));
// return Task.FromResult(true);
// // await t;
//}
}
}