Skip to content

Instantly share code, notes, and snippets.

@colinkiama
Last active July 19, 2023 17:47
Show Gist options
  • Save colinkiama/0c97cdb1381e3a2d06109e29ae14a3d6 to your computer and use it in GitHub Desktop.
Save colinkiama/0c97cdb1381e3a2d06109e29ae14a3d6 to your computer and use it in GitHub Desktop.
enum_to_nick() - Method for easily converting any enum into a string value in Vala e.g "HTTP.POST" to "POST"
public class Helpers {
public static string enum_to_nick (int @value, Type enum_type) {
var enum_class = (EnumClass) enum_type.class_ref ();
if (enum_class == null) {
return "%i".printf (@value);
}
unowned var enum_value = enum_class.get_value (@value);
if (enum_value == null) {
return "%i".printf (@value);
}
return enum_value.value_nick;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment