enum-flags

C#: Getting the correct keys pressed from KeyEventArgs' KeyData

I am trapping a KeyDown event and I need to be able to check whether the current keys pressed down are : Ctrl + Shift + M ? I know I need to use the e.KeyData from the KeyEventArgs, the Keys enum and something with Enum Flags and bits but I'm not sure on how to check for the combination. ...

Flags enum & bitwise operations vs. “string of bits”

A fellow developer suggested we store a selection of days of the week as 7-character string of 1’s and 0’s, i.e. “1000100” for Monday and Friday. I preferred (and strongly suggested) a solution with a Flags enum and bitwise operations, I think it's a cleaner way of doing this, and it should be easier to understand for other developers. ...

flag enum confusion C#

According to my code a=1, b=2, c=3 etc. I thought the flag would make a=1, b=2, c=4, etc [Flags] public enum someEnum { none, a, b, c, d, e, f, } How do i get what i intended(c=4, e=8)? and what does the [Flags] mean above? ...

WPF DataBinding to Flag Enum (in a PropertyGrid)

I need to have the ability to select multiple values as is the nature of a Flag enumeration from a WPF view (all be it, in a PropertyGrid). The properties in question are dynamic and no pre-defined DataTemplates can be used as the type of the properties will be discovered at runtime. (A DataTemplate which can detect if an enumeration i...

How to deal with calculated values with Dependency Properties on a custom WPF control

To summarize what I'm doing, I have a custom control that looks like a checked listbox and that has two dependency properties one that provides a list of available options and the other that represents a enum flag value that combines the selection options. So as I mentioned my custom control exposes two different DependencyProperties, ...

Random value from Flags enum

Say I have a function that accepts an enum decorated with the Flags attribute. If the value of the enum is a combination of more than one of the enum elements how can I extract one of those elements at random? I have the following but it seems there must be a better way. [Flags] enum Colours { Blue = 1, Red = 2, Green = 4 } ...

enum flags with name

Hi! I'm going to use enum flags for options to initialize my class. The enum is: namespace MCXJS { enum VARPARAM { STATIC = 1, CONST = 2 } //other things } If I'm right, in this case, to check for STATIC I need to do this: if (param & MCXJS::VARPARAM::STATIC) //... I know to do it this way: if (par...

C# - Help with [Flags] Enum & Extension Method

Hi Guys, I have the following enum: [Flags] public enum PostAssociations { None = 0x0, User = 0x1, Comments = 0x2, CommentsUser = 0x3 } As a starting note, im not sure if those flags are correct. I'm doing this so that i have a fluent way of defining "Includes" for Entity Framework (as the EF Include method takes a s...

C# extension method to check if an enumeration has a flag set

I want to make an extension method to check if an enumeration has a flag. DaysOfWeek workDays = DaysOfWeek.Monday | DaysOfWeek.Tuesday | DaysOfWeek.Wednesday; // instead of this: if ((workDays & DaysOfWeek.Monday) == DaysOfWeek.Monday) ... // I want this: if (workDays.ContainsFlag(DaysOfWeek.Monday)) ... How can I accomplish th...