I’d like to create an enumeration for ACCESS_MASK i have to use with P/Invoke, but i do not know what would be the best way for such an inplementation.
1. If it were possible:
[Flags]
enum ACCESS_MASK : uint
{
STANDARD_RIGHTS_REQUIRED = 0x000F0000,
SYNCHRONIZE = 0x00100000,
// Everything reused in the specific rights ...
}
[Flags]
enum PROCESS_ACCESS_MASK : ACCESS_MASK
{
// ...
PROCESS_ALL_ACCESS = STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | 0xFFFF,
}
2. Everything in one: (No automatic string representation possible)
[Flags]
enum ACCESS_MASK : uint
{
STANDARD_RIGHTS_REQUIRED = 0x000F0000,
SYNCHRONIZE = 0x00100000,
// ...
PROCESS_ALL_ACCESS = STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | 0xFFFF,
}
3. Split and rewrite: (Muuuuch duplicate code)
[Flags]
enum PROCESS_ACCESS_MASK : uint
{
STANDARD_RIGHTS_REQUIRED = 0x000F0000,
SYNCHRONIZE = 0x00100000,
// ...
PROCESS_ALL_ACCESS = STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | 0xFFFF,
}
4. Split and take from basic: (Specific enum doesn’t know anything about the basic values itself)
[Flags]
enum ACCESS_MASK : uint
{
STANDARD_RIGHTS_REQUIRED = 0x000F0000,
SYNCHRONIZE = 0x00100000,
// Everything reused in the specific rights ...
}
[Flags]
enum PROCESS_ACCESS_MASK : uint
{
// ...
PROCESS_ALL_ACCESS = ACCESS_MASK.STANDARD_RIGHTS_REQUIRED | ACCESS_MASK.SYNCHRONIZE | 0xFFFF,
}
Which option do you prefer, or are there any better ways for an ACCESS_MASK implementation?
Btw: whats a 0x100001 file access?
Edit: I know there is no enumeration inheritance and ACCESS_MASK : uint is nothing like that, but the imaginary PROCESS_ACCESS_MASK : ACCESS_MASK would be.
Assuming that you are hiding the P/Invoke details from the rest of the application, and that the
ACCESS_MASKvalues are only used very locally, I’d just put all options into one single enum – your option 2.Additionally, I’d mark the enum with
FlagsAttributeto indicate that it is treated as a bit field.