Re: [Vala] Array as big as an enum
- From: Al Thomas <astavale yahoo co uk>
- To: "vala-list gnome org" <vala-list gnome org>
- Subject: Re: [Vala] Array as big as an enum
- Date: Wed, 31 Aug 2016 18:10:31 +0000 (UTC)
----- Original Message -----
From: rastersoft <raster rastersoft com>
Sent: Wednesday, 31 August 2016, 18:51
Subject: Re: [Vala] Array as big as an enum
Even more: it would be great to be
able to access to the enums as strings too.
You can already.
To go from enum value to string just use the
to_string () method:
enum Test {
ONE,
TWO
}
void main () {
var a = Test.ONE;
print( "to_string() method: " + a.to_string() + "\n" );
print( "as %%s, but still needs to_string() method: %s\n", a.to_string() );
print( @"as template: $a\n" );
}
To go from string to enum value, first instantiate
your enum as an EnumClass then use the get_value_by_name ()
method. Similar to using the n_values field:
enum Test {
ONE,
TWO
}
void main() {
var a = (EnumClass)typeof (Test).class_ref ();
EnumValue? value = a.get_value_by_name ("TEST_ONE");
if (value != null) {
print ("%i\n", value.value);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]