I am trying out the new HasFlags features, and was wondering if the following should work:
enum.HasFlag(AccessRights.Read | AccessRights.Write)
... because it doesn't seem to...
DBAccessRights rights = (DBAccessRights)permission.PermissionFlags;
if (rights.HasFlag(DBAccessRights.WikiMode))
{
// works
}
if (rights.HasFlag(DBAccessRights.WikiMode | DBAccessRights.CreateNew))
{
// Doesn't work
}
DBAccessRights flags = DBAccessRights.WikiMode | DBAccessRights.CreateNew;
if (rights.HasFlag(flags))
{
// Doesn't work
}
Given the documentation, I'd expect that to return true if the value has both of those flags.
If you want it to test whether your value has either of those flags, you'll need
If that's not good readable enough for you, you may want to look at my Unconstrained Melody project. It so happens that that already has the functionality you want (as extension methods in
Flags.cs
):Those would make it clearer, IMO. They'd also avoid boxing, and be typesafe :)