aboutsummaryrefslogtreecommitdiffstats
path: root/reference/csharp/eina/src/eina_value.cs
blob: 0822798cc92513f6195ac1efe8c71e3265bf2da3 (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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
 * Eina Value examples.
 *
 * These examples demonstrate how to work with eina_value data and methods.
 * Eina_Value is a way to represent and pass data of varying types and to
 * convert efficiently between them.
 * Eina_Value can even define structs for managing more complex requirements.
 */

using System;

public class Example
{
    static void ValueInt()
    {
        int i;

        // Setting up an integer value type
        var int_val = new eina.Value(eina.ValueType.Int32);
        int_val.Set(123);
        int_val.Get(out i);
        Console.WriteLine("int_val value is {0}", i);

        // It can easily be converted to a string
        string str = int_val.ToString();
        Console.WriteLine("int_val to string is \"{0}\"", str);
    }

    static void ValueString()
    {
        string str;

        // Setting up an string value type
        var str_val = new eina.Value(eina.ValueType.String);
        str_val.Set("My string");
        str_val.Get(out str);
        Console.WriteLine("str_val value is \"{0}\"", str);

        // To string should have the same content
        string newstr = str_val.ToString();
        Console.WriteLine("str_val to string is \"{0}\"", newstr);
    }

    static void ValueConvert()
    {
        // Set up string and int types to convert between
        var str_val = new eina.Value(eina.ValueType.String);
        var int_val = new eina.Value(eina.ValueType.Int32);

        // Convert from int to string:
        int i1;
        string str1;
        int_val.Set(123);
        int_val.Get(out i1);
        int_val.ConvertTo(str_val);
        str_val.Get(out str1);
        Console.WriteLine("int_val was {0}, converted to string is \"{1}\"", i1, str1);

        // And the other way around!
        int i2;
        string str2;
        str_val.Set("33");
        str_val.Get(out str2);
        str_val.ConvertTo(int_val);
        int_val.Get(out i2);
        Console.WriteLine("str_val was \"{0}\", converted to int is {1}", str2, i2);
    }

    public static void Main()
    {
        efl.All.Init();

        ValueInt();
        Console.WriteLine("");

        ValueString();
        Console.WriteLine("");

        ValueConvert();
        Console.WriteLine("");

        efl.All.Shutdown();
    }
}