.NET Enums [Flags] & Bitwise Design Question

A hypothetical situation:

I have product features. These features are stored as BITWISE values in the database.

In my back-end code, I have a [Flags] enumerator that lists out all the features with its bitwise value assigned to each item in the enumerator.

This, obviously, gives us great benefit from a coding perspective, and, not to mention, faster I/O and fewer database records.

However, now I want to give someone the ability through a CMS interface, to add a new feature to the features table. Let's call it "Feature7"

So, "Feature7" gets added to the table with the next bit value assigned to it in the database. This is the 7th feature, so this will have a bit value of 64.

But now, the problem is that the [Flags] enum has to be manually updated to include the new feature and its new bit value. Which, doesn't really make the management of Features from CMS "automated"; there's still manual intervention needed from the developers.

So, my question is, using BITWISE, is there a way to make this fully automated without having to have code that generates a new DLL every time features are added to the table, like is suggested here:

http://stackoverflow.com/questions/725043/dynamic-enum-in-c-sharp

Let me know if that makes sense.

Obviously, I know this doesn't need to be done using bits, so I don't need suggestions in that regard.

Thanks in advance!
infotechelgAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AndyAinscowFreelance programmer / ConsultantCommented:
Using bits you could prefill the required enums, call them Feature7, Feature8....FeatureN.

However I usually don't use bitwise operators when the end user may need extra features.  I use a 1:n relation in two tables.  One table has the key value plus a user description.  The other table just stores the key along with the individual items.
0
infotechelgAuthor Commented:
Thanks for the reply, Andy. That's the problem: pre-filling the required enum values. I'm just wondering if anyone out there used BITWISE programming and was successful in automating processes.

Yeah, I know the 1:M database design is standard. But the appeal of bitwise is it's faster, it takes up less space, and it makes for really simple C# programming.
0
AndyAinscowFreelance programmer / ConsultantCommented:
Don't forget using the 1:n pattern means you don't need to write any code (extremely simple to code), the DB handles data integrity via the relation between the tables.
0
10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

Snarf0001Commented:
For my 2 cents worth, kind of share views with both of you.

InfoTech: I HEAVILY use flagged enums in numerous systems and databases for exactly the reasons you made.  Much less I/O on the db, fewer joins, and all around better performance.

But, as Andy points to, anytime where dynamic modifications are necessary (CMS), I have every single time gone back to 1:n in the db.  In my personal experience the code heaviness from attempting to make a dynamic enum both in general performance and code overhead outweighs the benefit of using an enum in the first place.
1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
infotechelgAuthor Commented:
Thanks, Snarf.  That makes total sense.
0
AndyAinscowFreelance programmer / ConsultantCommented:
Hmmm.  :-(
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.