Questions tagged [enum-flags]
167 questions
0
votes
1 answer
Set flags enum conditionally
I have an enum defined as follows
[Flags]
public enum Roles
{
[Descriptor("owner", "TheProficientLab representative")]
OWNER = 0,
[Descriptor("administrator", "Sets up users, questions, modules and reviews training and competency")]
…

americanslon
- 4,048
- 4
- 32
- 57
0
votes
3 answers
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 Enum types). How can I?
This code tell me:
operator '&'…

ProtoTyPus
- 1,272
- 3
- 19
- 40
0
votes
0 answers
Why did I have to use an int to combine these enum flag values together?
Perhaps someone can just explain the logic behind why this is actually an issue.
In my C# DLL I have a set of flag values that expose via the COM API:
[Flags]
[Guid("~~~")]
[ComVisible(true)]
public enum AssignmentType
{
None = 0,
Attendant…

Andrew Truckle
- 17,769
- 16
- 66
- 164
0
votes
2 answers
EnumFlags To List of Strings of Enum values C#
I'm trying to get a List of strings of the values of an Flags Enum
I have two enums
enum example {
name0 = 0,
name1 = 1,
name2 = 2,
name3 = 3
}
//And a flagged enum
[Flags]
enum example2 {
none = 0,
name1 = 1 <
0
votes
0 answers
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 debugging, producing the expected output.
However,…

Wör Du Schnaffzig
- 988
- 5
- 23
0
votes
2 answers
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 GenderEnum I would store male as 0, female as 1,…

Bubinga
- 613
- 12
- 29
0
votes
1 answer
How to bind to a Flag variable to a Xceed CheckComboBox
Given an object with a flag variable:
[Flags]
public enum fCondition
{
Scuffed = 1,
Torn = 2,
Stained = 4
}
public class AnEntity : TableEntity, INotifyPropertyChanged
{
public event…

Mark Wickman
- 83
- 1
- 9
0
votes
0 answers
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 truthy because 6 is equal to 3 + 2 + 1
How to…

Delbo ar
- 362
- 2
- 4
- 12
0
votes
3 answers
C# flag enum toggle by value or name
I have a Flags enum and would like to toggle some values by its (long) value.
[Flags]
public enum Permissions : long
{
Value0 = 0,
Value1 = 0x1,
Value2 = 0x2,
Value3 = 0x4,
//etc
}
I store the actual permission in the database…

Perrier
- 2,753
- 5
- 33
- 53
0
votes
1 answer
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 values of the Enum:
[Flags]
Enum TknType : byte
{
…

Prophet Lamb
- 530
- 3
- 17
0
votes
1 answer
Is there an easier way to parse an int to a generic Flags enum?
I've got a generic function to parse an object into a generic Enum.
However, I'm running into an issue when trying to safely parse an int into a [Flags] Enum.
Directly using Enum.ToObject() works to parse valid combinations, but will just return…

M. McCrary
- 35
- 3
0
votes
1 answer
What is the difference between local defined Enum-flags and Enum-defined flags?
I was working with Enums and I was looking for a way to group a range of enum-values to separate groups when I came across [Flags] for Enums.
I noticed that the example on ms-Docs was printing the array of the local declared enum bit-wise range (as…

Sebastian Lindblom
- 13
- 3
0
votes
2 answers
C# Check if Flags enum has only one value set
I have a Flags enum and want to assert that a given instance of it, is one of the primitive values, i.e. it has exactly one '1' in its binary representation, i.e. it's a power of two.
What's the best way to check this?
(I suppose "best" isn't…

Brondahl
- 7,402
- 5
- 45
- 74
0
votes
1 answer
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 bitwise operators.
I add 2 new values to this enum:…

A. Gladkiy
- 3,134
- 5
- 38
- 82
0
votes
1 answer
WSDL: How to create an enum with C# FlagsAttribute?
Basically, I created my WSDL and added a SimpleType with enum values: A, B, C. When I build my service with this wsdl I want the enum to be constructed with the FlagsAttribute, but how do I specify that in my wsdl?
I'm using svcutil.exe to generate…

michael
- 14,844
- 28
- 89
- 177