171 questions
1
vote
1
answer
87
views
How to check which enum values are set based on a combined value
I am having 5 checkboxes.
public enum animals : int
{
Cat = 1
,Dog = 2
,Mouse = 3
,Rat = 4
,Lizzard = 5
}
On saving my window I can sum up they checkboxes that are ...
-1
votes
1
answer
78
views
Enum Flags values reset on function call, UNITY
I'm trying to implement a simple switch between the control of 2 gameobjects in unity. Said switch can only happen when the entity you're switching from is grounded.
Base Flags values
The issue is ...
2
votes
4
answers
294
views
How to generically combine all bits (I mean OR all values) of a [FLAGS] enum, having only valid values (bits) declared in the resulting enum?
How to generically combine all bits (I mean OR all values) of a [FLAGS] enum, having only valid values (bits) declared in the enum?
Ex: [Flags] enum SuitsFlags { Spades = 1, Clubs = 2, Diamonds = 4, ...
2
votes
2
answers
388
views
Is there a way to prevent specific `enum.Flag` combinations?
If I have an enum class like so:
class TestFlag(enum.Flag):
A = enum.auto()
B = enum.auto()
C = enum.auto()
D = A | B # valid
Is it possible to specify a certain combination, such as, ...
0
votes
1
answer
1k
views
How can I get the active flags of a flag enum in an object in Typescript?
As the title suggests, I'm wondering if there's a way to do a similar thing as in C# with flag enums, where if the object is printed to IO, it prints out the flags that are active, instead of an ...
2
votes
2
answers
831
views
Can I decompose a Python Flag enum into its fundamental parts?
I have an enum that represents the directions you're allowed to move for a given cell in a maze:
class Direction(Flag):
NORTH = 1
EAST = 2
SOUTH = 4
WEST = 8
NE = NORTH | EAST
...
0
votes
1
answer
1k
views
Is there a solution for a bitwise logical AND (&) operator between two Enum values in C#
Consider the following simple Flags Enum in C#:
[Flags]
public enum CountingEnum
{
Zero = 0,
One = 1 << 0,
Two = 1 << 1,
Three = Two | One,
Four = 1 << 2,
...
0
votes
4
answers
2k
views
Check if flag contains any value of other flag
I would like compare two flags and see if they have any common value.
I'ld like having an extension method as weel in order to "speed up" coding (I'm going to use it often and on various ...
3
votes
0
answers
530
views
Best way to unset a flag in C when using Enum that is signed
I'm trying to use enum in C to create a flags variable, as discussed here: Flags, enum (C)
How should I reset a single enum flag, when the compiler represents the enum as signed?
Problem:
Say I ...
1
vote
2
answers
718
views
Is it possible to make a class which lets you stack enum Flags?
I'd like to use named constants whereever possible instead of providing literal values or longish function signatures with a lot of boolean args.
Therefore i like pythons enum.Flag or enum.Enum.
More ...
1
vote
1
answer
1k
views
Using [Flags] with multiple values in .Net 5.0.4 Entity Framework query
I have an Enum with [Flags] attribute like this:
[Flags]
public enum FlagStatus
{
Value1 = 1
, Value2 = 2
, Value3 = 4
}
And my query for EF like this:
x => x....
1
vote
1
answer
345
views
Get all values represent decimal value in flag enum
I am using typescript to declare enum of type flag as following
export enum OperatorEnum{
None = 0x0,
Equal = 0x1,
NotEqual = 0x2,
GreaterThan = 0x4,
LessThan = 0x10,
...
0
votes
0
answers
133
views
Debugging problems with deepcopy of class implementing __getattr__
I have a class which has an instance variable of type enum.Flag. It implements __getattr__ so that
i can return the boolean state of a flag given by name.
The code works fine when running without ...
0
votes
2
answers
592
views
Store multiple true values with an enum
I have recently started using enums to more efficiently store information in a database. I was wondering if there is some way to use them to store multiple true values. To elaborate, in a enum such as ...
0
votes
1
answer
306
views
JavaScript equivalent to .NET's Enum.HasFlag()
My .NET backend handle enum authorization with HasFlag()
Enum Foo {
0: Zero,
1: One,
2: Two,
3: Three,
..
}
5.HasEnum(Foo.One) is falsy because 5 is equal to 3 + 2
6.HasEnum(Foo.One) is ...
6
votes
3
answers
4k
views
Check if an enum contains more than one flag [duplicate]
I am trying to check if an "enum instance" contains more than one flag.
[Flags]
public enum Foo
{
Bar = 1,
Far = 2
}
var multiState = Foo.Bar | Foo.Far;
MoreThanOneFlag(multiState); // True
...
1
vote
2
answers
171
views
Why is StringSplitOptions tagged with the Flags attribute in C#?
I was looking at the summary of the StringSplitOptions enum and and then was surprised to see it has the Flags attribute applied to it.
The Flags enum is relevant for things like BindingFlags where ...
0
votes
1
answer
116
views
Check for Enum equals with Enum value composed from Enum flags
First of all I am very sorry for the title, but its quite impossible (for me) to come up with a fitting title.
The problem is as follows, I have a Enum where a value is composed from flags of two ...
2
votes
1
answer
244
views
Is it possible to do bitwise operations on string flags within the class definition?
I have created a custom class that extends enum.Flag:
from enum import Flag
class StrFlag(Flag):
def __new__(cls, verbose):
value = len(cls.__members__)
obj = object.__new__(cls)
...
1
vote
1
answer
305
views
How to store Processor Status flags' values with corresponding enum for 6502
I'm working on 6502 emulator in C++ as a part of my thesis. It has 6 registers, most of them just hold values but there's one special - Processor Status. It's 8 bit wide and each bit means a ...
9
votes
2
answers
18k
views
Check if an enum flag contains a certain flag value
In C# (using Unity working on a game) I have an enum with the [Flag] attribute. I have instantiated it twice. I would like a way to compare the two enums. Specifically if enum A (which will have ...
2
votes
1
answer
596
views
How can I use bitwise OR on an enum and an int?
I have a flag Enum called Role and an extension method called AddRole, that takes a Role enum and an int that works like a flag and only contains ones and zeros, where each 1 represents a role that a ...
0
votes
1
answer
223
views
Add new values to Enum and set them to true by default [Flags]
I have a enum:
[Flags]
public enum Role
{
Basic = 0,
A = 1,
B = 2,
C = 4,
D = 8
}
I store this value to DB in int column Role where Role = A | B | C (for example), so I'm using ...
1
vote
1
answer
563
views
WPF Enum Flags Dependency property in XAML property editor
I am developing custom WPF UserControl which has few Dependency Properties. One of the properties is enum flags. I am trying to check if it is possible to set this property from Designer in property ...
2
votes
2
answers
638
views
Operator '&' cannot be applied to operands of type 'T' and 'T', where T : Enum
I have this enum with Flags attribute
[Flags]
public enum Animal
{
Null = 0,
Cat = 1,
Dog = 2,
CatAndDog = Cat | Dog
}
And use C# 7.3 which allows type constraints like:
where T : ...