----- Original Message ----- > From: rastersoft <ras...@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); } } _______________________________________________ vala-list mailing list vala-list@gnome.org https://mail.gnome.org/mailman/listinfo/vala-list