summaryrefslogtreecommitdiff
path: root/src/examples/efl_mono/FunctionPointer01.cs
blob: 3eaa29d91c1482ceb41337ab93b53f268d854985 (plain) (blame)
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
using static System.Console;

public class ExampleFunctionPointer01
{
    private static bool static_called = false;

    private static int twiceCb(int n)
    {
        static_called = true;
        return n * 2;
    }

    public static void Main()
    {
        Eina.Config.Init();
        Efl.Eo.Config.Init();

        var obj = new Example.Numberwrapper();

        // Set internal value
        obj.SetNumber(12);

        // With static method
        obj.SetNumberCallback(twiceCb);

        var ret = obj.CallCallback();

        WriteLine($"Callback called? {static_called}.");
        WriteLine($"Returned value: {ret}.\n");

        // With lambda
        bool lamda_called = false;

        obj.SetNumberCallback(n => {
            lamda_called = true;
            return n * 3;
        });

        ret = obj.CallCallback();

        WriteLine($"Lambda called? {lamda_called}.");
        WriteLine($"Returned value: {ret}.\n");
    }
}