I'm currently dealing with a long enum with roughly 100+ elements, where the first word in each element is used to categorize the entries:
public enum UserPermissions{
FilesRead,
FilesWrite,
FoldersRead,
FoldersWrite,
NotesCreate,
NotesDelete,
NotesModify,
...
...
}
I would like to categorize the permissions into a more organized structure using namespaces such as:
UserPermissions.Files.Read;
UserPermissions.Notes.Modify;
The main issue here is to maintain compatibility with existing code by avoiding or minimizing refactoring needed. What is the best solution?
My current idea is to convert the enum to a class:
public class UserPermissions
{
public enum Files{
Read = 1,
Write = 2,
}
public enum Folders
{
Read = 3,
Write = 4,
}
...
...
}
But this will require refactoring old code such as UserPermissions.FilesRead
to UserPermissions.Files.Read
.