Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4237332
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T02:45:34+00:00 2026-05-21T02:45:34+00:00

I’m creating a flags enumeration in C#, similar to the following: [Flags] public enum

  • 0

I’m creating a flags enumeration in C#, similar to the following:

    [Flags]
    public enum DriversLicenseFlags
    {
        None = 0,

        Suspended = 1 << 1,
        Revoked   = 1 << 2,

        Restored  = 1 << 3,
        SuspendedAndRestored = Suspended | Restored,
        RevokedAndRestored   = Revoked   | Restored,
    }

A couple notes about my intentions here:

  • Suspended and Revoked are unique states that can, but don’t necessarily lead to a restore.
  • Restored should only be possible if the user has also been Suspended or Revoked (or both). It’s important to track specifically which event was the precursor to the restore.
  • A license can be both Suspended and Revoked (and Restored)

Also, I’m trying to stick to suggestions made in MSDN’s Designing Flags Enumerations. In particular:

  • Consider providing special enumeration values for commonly used combinations of flags.
    • SuspendedAndRestored and RevokedAndRestored will both be common.
  • Avoid creating flags enumerations when certain combinations of values are invalid.
    • This is my problem, because Restored is not valid unless at least one of Suspended and Revoked is set.

Ideally, I’d like a value for Restored to be present in the enum for internal usage, but only available to set publicly via some valid combination. Unfortunately, internal isn’t a valid modifier for enum values.

I’ve thought of a few alternatives, but each seems to have drawbacks:

  1. Keep Restored as a public value, note the limitations in comments and do a precondition check for invalid combinations on public APIs.

    This would work, and is likely the solution I will go with. However, it seems like their should be a cleaner solution.

  2. Use an enhanced, java-like enum as described here and define Restored as internal static.

    This would also work, but feels like overkill because I don’t need any of the other functionality at this point.

  3. Don’t define Restored as a value, but reserve the value for OR’ing, and for checking the value in consuming methods. i.e.:

    internal const int RestoredFlag = 1 << 3;
    [Flags]
    public enum DriversLicenseFlags
    {
        None = 0,
    
        Suspended = 1 << 1,
        Revoked   = 1 << 2,
    
        SuspendedAndRestored = Suspended | RestoredFlag,
        RevokedAndRestored   = Revoked   | RestoredFlag,
    }
    

This feels hacky me, both in how it’s defined and how it will be used internally.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T02:45:35+00:00Added an answer on May 21, 2026 at 2:45 am

    Why do you want to use Flags specifically? Is this not exactly what you are after?

    public enum DriversLicenseStatus
    {
        None = 0,
        Suspended,
        Revoked,
        SuspendedAndRestored,
        RevokedAndRestored,
    }
    

    It will certainly be easy to make sure that only “valid” transitions are made from within the property setters of the DriversLicenseStatus properties.

    If for some reason you definitely want to use Flags internally, then you can define a separate private enum DriversLicenseStatusFlags and convert from that to only expose DriversLicenseStatus values in your public interface.

    Another option which could be worth considering is splitting the enum into two values:

    bool IsActive;
    
    enum InactiveReason {
        None = 0,
        Suspended,
        Revoked,
    }
    

    The “AndRestored” cases would be those with IsActive == true and InactiveReason != InactiveReason.None.

    I get the distinct impression that you are over-engineering here. 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
public static bool CheckLogin(string Username, string Password, bool AutoLogin) { bool LoginSuccessful; // Trim
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.