summaryrefslogtreecommitdiff
path: root/src/examples/efl_mono/FunctionPointer01.cs
blob: c32f53cd5102c5f123b636f8acdbb69d92ef4550 (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
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");
    }
}