[Flags] Enum -- make it better

  • Thread starter Mobile Application Developer (MAD)
  • Start date
M

Mobile Application Developer (MAD)

I think that Microsoft should add a new feature to [Flags] so if values are
not specified in enum it defaults to sequence, {1, 2, 4, ... 2^(N-1)} where
N is largest number of bits allowed in an enum. A '#pragma' directive can be
added to displable.
Examples;
/// 1) NO CHANGE IN SEMANTICS
#pragma disable-flags
[Flags]
enum States { A, B, C, D}

/// 2) NO CHANGE IN SEMANTICS
[Flags]
enum States { A=1, B, C, D}

/// CHANGE IN SEMANTICS -- A = 1, B = 2, C = 4, D = 8
[Flags]
enum States { A, B, C, D}

/// CHANGE IN SEMANTICS -- A = 4, B = 8, C = 16, D = 32
[Flags:4]
enum States { A, B, C, D}

Would this not be very nice to have? How do I ask MS if they would add it to
languagge?
 
P

Pavel Minaev

I think that Microsoft should add a new feature to [Flags] so if values are
not specified in enum it defaults to sequence, {1, 2, 4, ...  2^(N-1)} where
N is largest number of bits allowed in an enum. A '#pragma' directive canbe
added to displable.
Examples;
   /// 1) NO CHANGE IN SEMANTICS
   #pragma disable-flags
   [Flags]
   enum States { A, B, C, D}

   /// 2) NO CHANGE IN SEMANTICS
   [Flags]
   enum States { A=1, B, C, D}

   /// CHANGE IN SEMANTICS  -- A = 1, B  = 2, C = 4, D = 8
   [Flags]
   enum States { A, B, C, D}

   /// CHANGE IN SEMANTICS -- A = 4, B = 8, C = 16, D = 32
   [Flags:4]
   enum States { A, B, C, D}

Would this not be very nice to have? How do I ask MS if they would add itto
languagge?

You can submit a feature request here:

http://connect.microsoft.com/VisualStudio/Feedback

On a side note, your proposal as described is backwards-incompatible
(for existing [Flags] enums), and thus unsuitable; and #pragma
definitely feels very wrong. A more reasonable suggestion would be
introducing a new context keyword modifier for enums that would change
the semantics, e.g.:

flags enum { A, B, C, D } // A=1, B=2, C=4, D=8

There's also one more thing. According to the Framework Design
Guidelines, all enums should have a member corresponding to value 0.
For [Flags] enums, this is typically named "None". Any such proposal
should take this into account.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top