I know I can multiply but being the lazy programming I am I do not want to.
Has anyone devised some sorcery to auto number the enums as powers of two?
Here’s the example I have just to make it concrete:
[Flags]
private enum Targets : uint
{
None = 0,
Campaigns = 1,
CampaignGroups = 2,
Advertisers = 4,
AdvertiserGroups = 8,
AffiliateGroups = 16,
Affiliates = 32,
Creatives = 64,
DetailedLeads = 128,
DetailedSales = 256,
ProgramLeads = 512,
CreativeDeployments = 1024,
CampaignCategories = 2048,
Payouts = 4096,
All = uint.MaxValue
}
Write the values as shifted bits and let the compiler do the math:
James’s suggestion is a good one, too. In fact I like this way even better. You could also write it like this: