2018-02-16 09:24:11 -08:00
|
|
|
|
|
|
|
/*
|
2019-01-15 04:19:08 -08:00
|
|
|
* Eina.List examples.
|
2018-02-16 09:24:11 -08:00
|
|
|
*
|
2019-01-15 04:19:08 -08:00
|
|
|
* These examples demonstrate how to work with Eina.List data and methods.
|
2018-02-16 09:24:11 -08:00
|
|
|
* 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;
|
|
|
|
|
2019-03-26 04:19:13 -07:00
|
|
|
public class Example : Efl.Csharp.Application
|
2018-02-16 09:24:11 -08:00
|
|
|
{
|
2018-11-06 01:39:14 -08:00
|
|
|
static Eina.List<string> CreateList()
|
2018-02-16 09:24:11 -08:00
|
|
|
{
|
2018-11-06 01:39:14 -08:00
|
|
|
var list = new Eina.List<string>();
|
2018-02-16 09:24:11 -08:00
|
|
|
|
|
|
|
list.Append("Adama");
|
|
|
|
list.Append("Baltar");
|
|
|
|
list.Append("Roslin");
|
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2019-06-28 15:46:12 -07:00
|
|
|
protected override void OnInitialize(string[] args)
|
2018-02-16 09:24:11 -08:00
|
|
|
{
|
|
|
|
var list = CreateList();
|
|
|
|
|
2019-01-15 04:19:08 -08:00
|
|
|
// Print our list with a simple foreach
|
2018-02-16 09:24:11 -08:00
|
|
|
Console.WriteLine("List size: {0}", list.Count());
|
|
|
|
Console.WriteLine("List content:");
|
|
|
|
foreach(string item in list)
|
|
|
|
Console.WriteLine(" {0}", item);
|
|
|
|
|
2019-01-15 04:19:08 -08:00
|
|
|
// Insert some more elements
|
2018-02-16 09:24:11 -08:00
|
|
|
list.Prepend("Cain");
|
|
|
|
// list.PrependRelative("Tigh", "Baltar"); // TODO: missing
|
|
|
|
|
|
|
|
Console.WriteLine("New list content:");
|
|
|
|
foreach(string item in list)
|
|
|
|
Console.WriteLine(" {0}", item);
|
|
|
|
|
2019-01-15 04:19:08 -08:00
|
|
|
// Promote an item to the top of the list
|
2018-02-16 09:24:11 -08:00
|
|
|
// 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);
|
|
|
|
|
2019-01-15 04:19:08 -08:00
|
|
|
// We can sort the list with any callback
|
2018-02-16 09:24:11 -08:00
|
|
|
// 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);
|
|
|
|
|
2019-01-15 04:19:08 -08:00
|
|
|
// And foreach can be in reverse too
|
2018-02-16 09:24:11 -08:00
|
|
|
Console.WriteLine("List content reverse sorted:");
|
|
|
|
foreach(string item in list.Reverse())
|
|
|
|
Console.WriteLine(" {0}", item);
|
|
|
|
|
|
|
|
list.Dispose();
|
|
|
|
|
2019-03-26 04:19:13 -07:00
|
|
|
Efl.App.AppMain.Quit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void Main()
|
|
|
|
{
|
|
|
|
var example = new Example();
|
2019-09-12 06:01:45 -07:00
|
|
|
example.Launch(Efl.Csharp.Components.Basic);
|
2018-02-16 09:24:11 -08:00
|
|
|
}
|
|
|
|
}
|