Support strings as enum values
I want to represent a restricted set of strings as an enum. I'd like to be able to do this:
enum WorkspaceOperation {
CREATE = "workspace/create",
RENAME = "workspace/rename",
DELETE = "workspace/delete",
}
This could generate the C code:
static const GEnumValue values[] = {
{WORKSPACE_OPERATION_CREATE, "workspace/create", "create"},
{WORKSPACE_OPERATION_RENAME, "workspace/rename", "rename"},
{WORKSPACE_OPERATION_DELETE, "workspace/delete", "delete"},
{0, NULL, NULL}
};
I want this to override GEnumValue.value_name
, so that if I do a workspaceOperation.to_string ()
I get the specified string back.
I first considered just requesting a CCode attribute [CCode (value_name = "workspace/create")]
but I thought this syntax looked nicer. The only downside is that you can not specify the numeric value of the enum value anymore, so maybe the CCode is the better solution here.