Last active
July 19, 2023 17:47
-
-
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"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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