Calculating Enum Values that aren't powers of two using the current enumeration values

// SortedSet is not necessary but it has convenient Min and Max properties.
SortedSet<MyEnum> enumValues = new SortedSet<MyEnum>();
foreach (MyEnum e in Enum.GetValues(typeof(MyEnum)))
enumValues.Add(e);
// enumValues.Max * 2 to check all combinations including the last flag.
for (int i = (int)enumValues.Min + 1; i < (int)enumValues.Max * 2; i++)
MyEnum currentlyChecked = (MyEnum)i;
// if there's no equivalent of i defined in MyEnum
if (!enumValues.Contains(currentlyChecked))
string representation = "";
// Iterate over all MyEnum flags which underlying value is lower than i
// and add those flags which are contained in (MyEnum)i to the string representation
// of the value missing from the MyEnum enumeration.
foreach (MyEnum lowerValue in enumValues.Where(e => (int)e < i))
if (currentlyChecked.HasFlag(lowerValue))
representation += lowerValue.ToString();
if (String.IsNullOrEmpty(representation))
representation = "[MISSING FLAG]";
if (representation.Contains("None") | representation.Contains("Undefined"))
representation = representation.Replace("Undefined", "");
representation = representation.Replace("None", "");
Console.WriteLine("Missing value: {0} - {1}", i, representation);
I have the above code, which works great when The type of the Enumeration is known. However, the actual code is loading the Enumerations through reflection and placing the values and names into a Dictionary <int, string>. I need to be able to use the
above code with my dictionary to achieve the same result, however  when I try to modify the above code for the dictionary, I run into a problem.
The Enum that it is scanning looks like this:
[Flags]
public enum Method
Undefined = 0,
Site = 1,
Manual = 2,
API = 4
and the output should be
3: SiteManual - This works fine
5: PortalAPI
6: ManualAPI
7: SiteManualAPI
However, the output it is giving me is
3: SiteManual
5: SiteManualAPI
6: SiteManualAPI
7: SiteManualAPI
How do I adapt the above code so I can calculate the proper values without having Enum type, since I can't seem to create the sorted set from the reflection type.

I guess you want something like this:
int someValue = 5;
string result = ((int[])Enum.GetValues(typeof(Method)))
.Aggregate("", (a, s) =>
if ((someValue & s) != 0)
a += Enum.GetName(typeof(Method), s) + " ";
return a;
// someValue=5 -> Site API
// someValue=6 -> Manual API
// someValue=7 -> Site Manual API
// someValue=13 -> Site API

Similar Messages

  • Bottom row of the keyboard is not working in a vertical orientation on the iPhone 3Gs. the "slide to unlock" and all keys on the calculator on both orientation works fine. I can use the keyboard on horizontal orientation.

    Bottom row of the keyboard is not working in a vertical orientation on the iPhone 3Gs. the "slide to unlock" and all keys on the calculator on both orientation works fine. I can use the keyboard on horizontal orientation. The tabs on bottom of all apps also work fine.
    I have already tried holding down the power button and home button for 10 seconds, but no difference.

    I've had this problem on and off for the last few weeks (around, but not directly related, to upgrade to 6.1...can't remember if was before or after)....I'm very convinced it's a software problem (as there have been times when the bottom row works perfectly, without any need to "press" differently or anything).
    However, it seems to be a rather resilient software issue, as a full restore does not consistently fix it, and it applies to more than just the keyboard; if I open a drawing app, there's definitely a row (about 4mm up from the edge of the screen closest to home button) where I cannot draw.
    It's happened 4 times now.  Originally it went away with a restore from backup, then worked for 2 more days.  The second and third times, it went away with a full restore (although I did two full restores in between those two restores that did nothing, so restore didn't consistently fix it)....and it seemed to return in the most random of circumstances. 
    I paid very close attention to what apps I was using the last time it was working so that I could spot which app, if any, might be causing the issue.  I deleted several apps, I stopped using the games and many other apps.   I only used three apps between it working fine and starting up as a problem again: mail, safari and messages.
    I was convinced it was mail, as it happened this morning when I picked up my phone off the bedside table to respond to a new email.  It was working when I went to bed.  I picked up the phone when it buzzed, hit the email app, hit reply and started to type....**** bottom row wasn't working again.
    However, tonight I did 2 things....one of them worked because it went back to normal (sorry, I don't know which as I was exasperated and trying a number of things). 
    The two things I did between a broken keyboard and a working keyboard were:
    1) adding a second keyboard (English(Canada)), changing to this keyboard, and changing back
    2) disabling Siri...and then turning it back on...and then disabling Siri's "Raise to Speak"
    In retrospect, I wonder if it actually was the "Raise to Speak" that was putting the phone into a weird state, and might explain why the phone would just "suddenly" start behaving strangely when I picked it up.  Of note, the "raise to speak" hasn't actually triggered Siri to come on in months anyway.
    Regardless, the keyboard is back to normal now...and I'm just going to leave "Raise to Speak" off.  I've put the keyboard back to just "English" with no alternates and Siri remains on otherwise without issue.

  • I would like to know if there is a setting i can change that will use the current tab i'm on when opening a group of links in tabs.

    Until i upgraded to firefox 8, when i opened a group of tabs (right click on a folder of bookmarks and open all in tabs option), it would use the current tab to as the first of the links and open the rest to the right of that tab. Now that has changed. I don't mind except for not using the tab i'm on. That is somewhat annoying, especially if that is how i browse most of the time. As the first thing i do is open a group of tabs when i start firefox, the first tab has to be closed manually as it did not before and this is annoying to me.

    * You could use different Profiles, each with its' own set of homepages.
    https://support.mozilla.com/en-US/kb/Profiles
    * You could load the default homepage and then open a folder of bookmarks in new tabs by middle-click on the folder or using a right-click & Open All in Tabs.

  • Pages app unexpectedly quit whilst I was in the middle of a document. I can now not open it AT ALL. I find it's not just that particular document that won't open, but any of my Pages docs will not open using the current version of Pages. Any help?

    Pages app unexpectedly quit whilst I was in the middle of a document. I can now not open it AT ALL. I find it's not just that particular document that won't open, but any of my Pages docs will not open using the current version of Pages. The reports of the app unexpectedly closing each time, automatically went to Apple, but I am not sure what happens with them then. Does anyone know how to help me with this? We live in a very isolated region so rely on internet help. Thanks

    I also managed to read a few other discussions about Pages and files not being able to open. I actually went to the last back-up and restored the computer from that and everything seemed to work ok again, which is great!...advice from another discussion I think you may have been involved in PeterB. Thanks for the advice...also this advice, as I will make a note of trying to open using the Shift key if it happens again and see what happens...might be an easier first option than restoring from a back-up. Thans heaps for the help!
    I was interested to read some of the other discussions where it was stated that Pages '09 seems to be a better option to use. I have both installed, so I will lkeep this in mind. Thanks heaps!

  • I updated my first generation iPad to version 5.1.1 and won't go past the setup screen that asks if I want to use the iPad locator. I can go back but can't get any further.

    I updated my first generation iPad to version 5.1.1 and won't go past the setup screen that asks if I want to use the iPad locator. I can go back but can't get any further

    I just updated my original iPad 32 GB WiFi to iOS 5.1 about fifteen minutes ago.  But I did it with the system restore feature in iTunes.  So it wiped out everything on my iPad.  But it did work.  Then I restored an earlier backup and all went fine.  Maybe you could try backing up your iPad and then using Restore to get it back to factory settings to see what happens. 

  • I am facing issue when opening flash files in Flash CC. (error:- This file was created with a later release of Flash Professional and might contain new features that would be lost when saved in the current format.)

    I am facing issue when opening flash files in Flash CC. (error:- This file was created with a later release of Flash Professional and might contain new features that would be lost when saved in the current format.)

    Wow. Okay...
    I'll let the real veterans in this forum tackle your issues one after the other. But, I can tell you, all will be well.
    My only comment would be re: your computer specs:
    BJReis wrote:
    .  This may be due to somewhat older equipment:
    GHz Intel Core Duo MacBook Pro with a 4GB memory computer with Ddr3 running OSX 10.8.4
    To be completely honest, FCPX is a RAM hog. It just is. But, RAM is relatively cheap, and the pay-off is good.
    4GB is right on the edge, IMHO. 16G is ideal.
    I wish you luck, hang in there, and standby for more help.

  • How can i set songs within a playlist, or an entire playlist, so that they are not included when using the shuffle function on IPOD Classic? Is this possible?

    How can i set songs within a playlist, or an entire playlist, so that they are not included when using the shuffle function on IPOD Classic?
    Is this possible?

    You can set any song to Skip when shuffling.
    In your iTunes Library, highlight the song and right-click/Get Info. On the Options tab is the Skip when shuffling box. Select that and then Sync the iPod with your Library.

  • Sorry but I think this wrong, I know that in Colombia there and two of the three operators already have 4G/LTE networks, what happens is that the iPhone should be expected to send the update software for computers that have this tercnologia activate them,

    sorry but I think this wrong, I know that in Colombia there and two of the three operators already have 4G/LTE networks, what happens is that the iPhone should be expected to send the update software for computers that have this tercnologia activate them, that my Iphone or receiving 5 supports 4G LTE,
    Thank you for your attention

    Apple needs to test the carrier if they offer LTE as expected.
    If your country/carrier is not on the list then there's no LTE on your iPhone.
    http://www.apple.com/iphone/LTE/
    It's between the your carrier and Apple. There's nothing you can do except feedback to Apple:
    http://www.apple.com/feedback/iphone.html

  • Before using the current Mac version Yosemite, I did not have an Administrator password.  It seems now that one is required to unlock and make changes in settings.  I have tried all my usual passwords but to no avail.  any ideas???

    Before using the current Mac version Yosemite, I did not have an Administrator password.  It seems now that one is required to unlock and make changes in settings.  I have tried all my usual passwords but to no avail.  any ideas???

    Boot into Recovery. OS X: About OS X Recovery - Apple Support
    Select Terminal from the Utilities menu.
    At the prompt type,
    resetpassword
    Hit return.
    Follow the prompts in the utility to select hard drive, then user.
    Reset the password.
    Exit the utility and restart.
    You will need to log in with your new password, but your keychain will not be reset.
    I’m not sure what access you’ll have to the old keychain since it didn’t have a password. You may be able to get into the keychain and reset the password to match your login password.

  • When i try to open my flash player in system preferences i get the message that system preferences quit unexpectedly while using the flash player plugin.

    when i try to open my flashplayer in system preferences i get the message that system preferences quit unexpectedly while using the flashplayer plugin. thanks for any help

    The problem has been fixed with the most recent OS X software update.

  • Apps that arbitrarily restrict which users may use the App, such as by location or carrier, may be rejected

    Hello,
    I have an inquiry, this section:
    Apps that arbitrarily restrict which users may use the App, such as by location or carrier, may be rejected
    We have an mBanking app to be built and the Bank is insisting on forcing a mandatory update when there is a need
    and the user should be restricted from logging in in such case (as a security update or important bug fixes).
    Does the above fit in what will be rejected? Will the application be rejected in such a case? if so are there any workarounds?
    Thanks
    nsawaya

    No, no, and no.
    Sorry, but this is Apple we’re talking about here.
    Bob

  • I have a HP Pavilion dv2910us that I am try to recover using the HP recovery disks.

    I have a HP Pavilion dv2910us that I am try to recover using the HP Vista Home Premium recovery disks. Recovery disk #1 worked and prompted me to insert disk #2, disk #2 was inserted and ran until only 20% of installing original content was reached. CD/DVD rom light on lower left of the notebook is not lit, wireless light is lit, running. Program ran slowly to reach the 20% mark, over three hours at one or two percentage points at a time. Then for the next 12 hours nothing, no keys or commands on the keyboard have been touched. Please advise next step, thank you.

    Hi:
    If you can't get the recovery disks to work (I can't help you there), and you can still read all 25 characters of your Vista product key on the bottom of your PC, you can make your own Vista installation disk and use the product key to activate it.
    Here's how:
    If you're up to a slight but rewarding challenge you can make your own if you can read your 25 character Vista product key on the PC.
    Just download the 3 files you need at the link below, and read all of the instructions to create a bootable DVD installation disk using imageburn.
    Disregard the part of the text under the first screen shot about "extract the files to the Vista folder."
    The files were already extracted to that folder when you ran the X14.exe file by reading the text on top of the first screen shot.
    The other thing I noticed is on the 4th screen shot, where it shows Developer ID Microsoft Corporation. I had to type Microsoft Corporation in myself, and then the other codes automatically populated.
    When I went to compile the ISO file, ImageBurn gave a message that about a WIM file and ISO, and if I wanted to burn it in a different format.
    I selected No, make the ISO file.
    It was not that hard to do. I burned both the 64 bit disk and the 32 bit disk in case I ever need them.
    I tested both of them on my hp dc7100 CMT desktop PC, they worked perfectly.
    When you enter the product key, it knows what version of Vista you have.
    http://en.community.dell.com/support-forums/software-os/w/microsoft_os/3317.2-3-microsoft-windows-v....
    After you successfully install Vista, you can then install the drivers from your PC's support and driver page.
    Paul

  • How do I change the sound that is played when you iI use the Find my IPhone feature to make it alot louder?  The current sound is very faint, difficult to find as I am hard of hearing.

    How do I change the sound that is played when you I use the Find my IPhone feature to make it alot louder?  The current sound is very faint, difficult to find as I am hard of hearing.

    Hi,
    Tap the iPod icon in the Dock. Then tap the Airplay icon just to the right of the volume slider.
    Make sure the iPad speakers are selected, not your wireless.
    Carolyn 

  • Any advice on how to switch to ICloud on my 3g IPhone?  I am supposed to install OS 5, but the dialogue box says that my 4.2.1 OS is the current version and does not give me the option of downloading OS5.  Apple says I have to be running 5 to switch.

    Any advice on how to switch to ICloud on my 3g IPhone?  I am supposed to install OS 5, but the dialogue box says that my 4.2.1 OS is the current version and does not give me the option of downloading OS5.  Apple says I have to be running OS5 to switch.

    "iCloud requires iOS 5 on iPhone 3GS or later, iPod touch (3rd and 4th generation), iPad, or iPad 2; a Mac computer with OS X Lion
    From here >  http://www.apple.com/icloud/

  • Is normal that appear a spot  when i use the camera? and when you apply the zoom, the spot increases its size?

    Is normal that appear a spot  when i use the camera? and when you apply the zoom, the spot increases its size?

    Morning alex navarro,
    Thanks for using Apple Support Communities.
    For troubleshooting on this, take a look at this article:
    iPhone: Hardware troubleshooting
    http://support.apple.com/kb/TS2802
    Ensure the camera lens is clean and free from any obstructions. Use a microfiber polishing cloth to clean the lens.
    Third-party cases can interfere with the autofocus/exposure feature and the flash (iPhone 4 only); try removing the case if you have image-quality issues with photos.
    If your iPhone has a front and rear camera, try switching between them to verify if the issue persists on both.
    Hope this helps,
    Mario

Maybe you are looking for