blob: 5f4559a781cd5627b223d2ad30f7f5439e5dcaa3 (
plain)
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
|
using System;
using System.Threading.Tasks;
public class Class1
{
protected void InvokeAction (Action action)
{
action ();
}
public void Bar()
{
}
async Task Test ()
{
Task.Run(async () =>
{
var implementor = ServiceLocator.GetImplementor<IInterface1> ();
string message = null;
bool result = await implementor.Foo ((s) => message = s);
InvokeAction (() => Bar ());
}).Wait ();
}
interface IInterface1
{
Task<bool> Foo(Action<string> action);
}
class CIInterface1 : IInterface1
{
public Task<bool> Foo (Action<string> action)
{
action ("msg");
return Task.FromResult (false);
}
}
static class ServiceLocator
{
public static TService GetImplementor<TService>() where TService : class
{
return (TService) (object) new CIInterface1 ();
}
}
public static void Main ()
{
new Class1 ().Test ().Wait ();
}
}
|