aboutsummaryrefslogtreecommitdiffstats
path: root/reference/csharp/eina/src/eina_list.cs
blob: ecdf7d31634f8512afd22dcbd1db16b5be6df36e (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

/*
 * Eina List examples.
 *
 * These examples demonstrate how to work with Eina_list data and methods.
 * We create a simple list of names by appending strings to an empty list
 * and then run various mutations and print each result.
 */

using System;
using System.Linq;

public class Example
{
    static Eina.List<string> CreateList()
    {
        var list = new Eina.List<string>();

        list.Append("Adama");
        list.Append("Baltar");
        list.Append("Roslin");

        return list;
    }

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

        var list = CreateList();

        // print our list with a simple foreach
        Console.WriteLine("List size: {0}", list.Count());
        Console.WriteLine("List content:");
        foreach(string item in list)
            Console.WriteLine("  {0}", item);

        // insert some more elements
        list.Prepend("Cain");
//         list.PrependRelative("Tigh", "Baltar"); // TODO: missing

        Console.WriteLine("New list content:");
        foreach(string item in list)
            Console.WriteLine("  {0}", item);

        // promote an item to the top of the list
        // TODO: implement ?
//         list.PromoteList(list.NthList(1));
//         list.Remove("Cain");
//
//         Console.WriteLine("List content after promotion:");
//         foreach(string item in list)
//             Console.WriteLine("  {0}", item);

        // we can sort the list with any callback
//         list.Sort((string strA, string strB) => { return strA.Compare(strB); }); // TODO: FIXME custom sort
        list.Sort();
        Console.WriteLine("List content sorted:");
        foreach(string item in list)
            Console.WriteLine("  {0}", item);

        // and foreach can be in reverse too
        Console.WriteLine("List content reverse sorted:");
        foreach(string item in list.Reverse())
            Console.WriteLine("  {0}", item);

        list.Dispose();

        Efl.All.Shutdown();
    }
}