Bitfield With 3 States...?
Posted
by TheCloudlessSky
on Stack Overflow
See other posts from Stack Overflow
or by TheCloudlessSky
Published on 2010-05-10T17:28:25Z
Indexed on
2010/05/10
17:34 UTC
Read the original article
Hit count: 271
I'm trying to create an authorization scheme for my ASP.NET MVC application where an Enum is used to set permissions. For example:
[Flags]
enum Permissions
{
ReadAppointments = 1,
WriteAppointments = 2 | ReadAppointments,
ReadPatients = 4,
WritePatients = 8 | ReadPatients,
ReadInvoices = 16,
WriteInvoices = 32 | ReadInvoices
...
}
But I don't really like that because it really doesn't make it clear that Write always includes Read.
I then realized that a requirement would be that a user might have NO access to, for example, Appointments.
Essentially, I'd want a "bitfield" with 3 states: none, readonly, full (read/write). I'd like to still use an enum bitfield since it's easy to store in a DB (as an int). Also it's very easy to see if a permission is set.
Does anyone have any idea how this could be easily accomplished using an Enum... or am I going in the completely wrong direction?
© Stack Overflow or respective owner