Solution for lots of flags

Hi. When I need to have rights management in my programs, I usually make an enum "Rights" as [Flags] type long and do like

Invalid = -1,
None = 0,
AddGame = 1,
DelGame = 2,
LaunchGame = 4,
EditGame = 8
..etc


I like because it's simple bitwise and I made an extension method so I can just do like

function DeleteGame(Game game) {
if (!ActiveUser?.Rights.HasPermission(Rights.DeleteGame) ?? false) return;


However... I'm doing a big complex app and it's gonna have more rights than I have bits in a long. What is a good way to handle it at that point? I figured I could do enums like

Rights_Context1
Rights_Context2
..etc


then I was trying to figure out how to store them in the user. I figured maybe

public List<Enum> Rights

then load them all into there, but then how do I check them? Loop and check what type each entry is then compare? That seems awkward.

Is there any easy solution for having large amounts of flags in an enum? I assume I need a bitwise enum because I want to store the data in the db, and a bigint seemed the easiest way. I suppose I could do a permissions related table then make single entries per flag but that seems very inefficient.
Was this page helpful?