Questions tagged [enum-flags]

167 questions
3
votes
1 answer

Is System.Reflection.TypeAttributes a sick enum type with the FlagsAttribute?

The enum type System.Reflection.TypeAttributes appears rather pathological. It carries the [Flags] attribute and has no less than four synonyms for the constant zero. From Visual-Studio-generated "metadata": #region Assembly mscorlib,…
Jeppe Stig Nielsen
  • 60,409
  • 11
  • 110
  • 181
3
votes
1 answer

How to bind the multiple selected items of list box in xaml

I have Flags Enum value which I have bound into the item source of listbox. I have used SelectionMode as multiple. I want assign all the selected items of the listbox to a flag Enum property. How can I bind the selected items? private void…
MS.Dev
  • 35
  • 1
  • 4
3
votes
2 answers

.NET enum.HasFlag() bug?

I'm using the following .NET 4.5.2 code: if (this.ContainsFocus && keyData == (Keys.Tab|Keys.Shift)) { ... } Why is the expression true when ContainsFocus (bool = true) and keyData (System.Windows.Forms.Keys) is Keys.O | Keys.Shift? As you can see…
CrazyTea
  • 297
  • 1
  • 3
  • 13
3
votes
1 answer

Serialize Flags enum with two equal values

I want to define a flag enum like the following: [Flags] [Serializable] public enum Numbers { [XmlEnum(Name = "One")] One = 0x1, [XmlEnum(Name = "Two")] Two = 0x2, [XmlEnum(Name = "Three")] Three = 0x4, [XmlEnum(Name =…
Brian
  • 1,201
  • 2
  • 14
  • 26
3
votes
5 answers

How to cast int value to list int value of Flag enums

I have this flag enum: public enum DataAccessPoliceis { None = 0, A = 1, B = 2, C = 4, D = 8, E = B | C | D, // 14 All = A | E // 15 } I want to get int value (or list of int values for complex enum item)…
Sayed Abolfazl Fatemi
  • 3,678
  • 3
  • 36
  • 48
3
votes
2 answers

Best way to store status flags

Looking for the best way to store flags for the following scenario. My application has to send certain number of notifications or reminders to users in a specific interval.I am planning to write a batch job to do it. To avoid resending of reminders…
g0c00l.g33k
  • 2,458
  • 2
  • 31
  • 41
3
votes
1 answer

Why does MSDN state that HasFlag is *designed* to work with FlagsAttribute?

The question What does the [Flags] Enum Attribute mean in C#? doesn't ask what I'm asking and also doesn't answer it. If there is such answer in that question, please, state which one (link) in the comments rather than mindlessly and erroneously…
talles
  • 14,356
  • 8
  • 45
  • 58
3
votes
2 answers

What is the internal logic for Enum HasFlag function implementation

Can someone please help me to understand the internal logic of HasFlag method for a enum class? Let me first explain my requirement. I have already created an enum with flag attribute, and then used HasFlag() function to get selected combination…
Subhendu Roy
  • 63
  • 3
  • 8
3
votes
2 answers

What is the "|=" operator in C#?

In researching the cause of a bug, I came across this line of code: Status |= (int)states.Reading; What is the "|=" operator in C#? "Status" is defined thusly: public static int Status ...with an accessor and mutator (or "getter" and "setter"),…
3
votes
4 answers

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?
user34537
2
votes
1 answer

Nhibernate QueryOver by Enum Flags

I have a query by QueryOver : public IList SearchTest(PersonEnumType type) { var q = SessionInstance.QueryOver(); q = q.Where(x => (x.PersonEnumType & type) == type); return q.List(); } and PersonEnumType is a…
Ehsan
  • 3,431
  • 8
  • 50
  • 70
2
votes
3 answers

What are the disadvantages of using a flags enum for permissions?

In trying to implement role based security for a web app, I have a table in the database for Permissions, Roles, Users and UserRole (i.e the assignment of users to roles). Each role has a set of permissions. The permissions are defined as a C# flags…
Krishna
  • 2,997
  • 1
  • 23
  • 31
2
votes
1 answer

Python mypy warning of incompatible type when using Enum Flag

I am trying to make a variable that can be from a set of enum values, and then select a specific one when using it elsewhere. from enum import Flag, auto class MyEnum(Flag): FOO: int = auto() BAR: int = auto() MOO: int = auto() def…
2
votes
2 answers

Bind each value of an enum to a checkbox Blazor

I have an [Flags] Enum that contains some datapoints that I want to collect. My goal is to display and bind each value(each bit) as an individual checkbox for the user to check. However, I do not know how to bind individual values of an Flags enum…
Bubinga
  • 613
  • 12
  • 29
2
votes
3 answers

Python enum.Flag with one flag that is used by some others

I would like to define a set of flags (subclassed from enum.Flag), with some flags which are defined based on others. This is similar to the white flag in the example: https://docs.python.org/3/library/enum.html#flag, but it is not just a…
markmuetz
  • 9,334
  • 2
  • 32
  • 33