Provides extensions to help with common enum operations.
More...
|
static bool | HasFlag< T > (this T enumValue, T flag) |
| Tests if a "flag" enum contains the required flag. Enums which have values declared as powers of 2 can be or'd together to provide a final value, eg when using BindingFlags: var method = typeof(SomeClass).GetMethod("foo", BindingFlags.Public | BindingFlags.Instance);.
|
static bool | HasFlags< T > (this T value, T flag1, T flag2, params T[] moreFlags) |
| Tests for multiple flags in an int value.
|
static bool | HasFlags (this int value, int flag1, int flag2, params int[] moreFlags) |
| Tests for multiple flags in an int value.
|
static bool | HasFlags (this int value, IEnumerable< int > flags) |
| Tests for multiple flags in an int value.
|
static T | WithFlag< T > (this T enumValue, T flag) |
| Returns a new value that is the original enum with the required flag added.
|
static int | WithFlag (this int value, int flag) |
| Returns a new value that is the original enum with the required flag added.
|
static T | WithoutFlag< T > (this T enumValue, T flag) |
| Returns a new value that is the original enum value without the provided flag.
|
static int | WithoutFlag (this int value, int flag) |
| Returns a new value which is the original integer value without the provided integer flag.
|
static bool | HasFlag (this int value, int flag) |
| Provides the integer analogy to testing flags in an enum value, since the former relies on integer math anyway. This essentially tests if the flag's on-bits are all on in the value, eg 6.HasFlag(2); // true.
|
Provides extensions to help with common enum operations.
◆ HasFlag()
bool PeanutButter.Utils.FlagExtensions.HasFlag |
( |
this int | value, |
|
|
int | flag ) |
|
static |
Provides the integer analogy to testing flags in an enum value, since the former relies on integer math anyway. This essentially tests if the flag's on-bits are all on in the value, eg 6.HasFlag(2); // true.
- Parameters
-
- Returns
◆ HasFlag< T >()
Tests if a "flag" enum contains the required flag. Enums which have values declared as powers of 2 can be or'd together to provide a final value, eg when using BindingFlags: var method = typeof(SomeClass).GetMethod("foo", BindingFlags.Public | BindingFlags.Instance);.
- in this case, one could do something like: if (flags.HasFlag(BindingFlags.Public)) { // do whatever one does with public members }
- Parameters
-
- Template Parameters
-
- Returns
◆ HasFlags() [1/2]
bool PeanutButter.Utils.FlagExtensions.HasFlags |
( |
this int | value, |
|
|
IEnumerable< int > | flags ) |
|
static |
Tests for multiple flags in an int value.
- Parameters
-
- Returns
◆ HasFlags() [2/2]
bool PeanutButter.Utils.FlagExtensions.HasFlags |
( |
this int | value, |
|
|
int | flag1, |
|
|
int | flag2, |
|
|
params int[] | moreFlags ) |
|
static |
Tests for multiple flags in an int value.
- Parameters
-
value | |
flag1 | |
flag2 | |
moreFlags | |
- Returns
◆ HasFlags< T >()
Tests for multiple flags in an int value.
- Parameters
-
value | |
flag1 | |
flag2 | |
moreFlags | |
- Template Parameters
-
- Returns
◆ WithFlag()
int PeanutButter.Utils.FlagExtensions.WithFlag |
( |
this int | value, |
|
|
int | flag ) |
|
static |
Returns a new value that is the original enum with the required flag added.
- Parameters
-
- Returns
◆ WithFlag< T >()
Returns a new value that is the original enum with the required flag added.
- Parameters
-
- Template Parameters
-
- Returns
◆ WithoutFlag()
int PeanutButter.Utils.FlagExtensions.WithoutFlag |
( |
this int | value, |
|
|
int | flag ) |
|
static |
Returns a new value which is the original integer value without the provided integer flag.
- Parameters
-
- Returns
◆ WithoutFlag< T >()
Returns a new value that is the original enum value without the provided flag.
- Parameters
-
- Template Parameters
-
- Returns
The documentation for this class was generated from the following file:
- source/Utils/PeanutButter.Utils/FlagExtensions.cs