Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom names to enumeration values

I have an enumeration of values that come through an API.

Those names are good but there is one I want to change with data annotations but how do you do that?

My enumeration looks like :

public enum TopicType
{
    All = 0,
    Message=1,
    CalendarEvent=2,
    Upload=4, 
    ToDo=8,
    ToDoList=16,
    Document=32
}

I want to change the "ToDo" to "ToDoItem" when I'm coding but I can't change the value in the enumeration due to serialization of my enum-object so I'll have to use data annotations, any suggestions?

like image 541
Tom Kerkhove Avatar asked Dec 16 '22 19:12

Tom Kerkhove


1 Answers

Regardless of why you want to change ToDo to ToDoItem (separate discussion), you can easily achieve it using the following approach:

public enum TopicType
{
  All = 0,
  Message=1,
  CalendarEvent=2,
  Upload=4, 
  [Display(Name = "ToDoItem")]
  ToDo=8,
  ToDoList=16,
  Document=32
}

Hope this helps

like image 69
Display Name Avatar answered Jan 04 '23 23:01

Display Name