Class EnumExtensions
- Namespace
- Plugin.BaseTypeExtensions
- Assembly
- Plugin.BaseTypeExtensions.dll
Provides extension methods for working with enum types, including flag manipulation and description retrieval.
public static class EnumExtensions
- Inheritance
-
EnumExtensions
- Inherited Members
Methods
AllAsArray<T>()
Returns all values of the specified enum type as an array.
public static IEnumerable<T> AllAsArray<T>()
Returns
- IEnumerable<T>
An array of all enum values.
Type Parameters
TThe enum type.
AllAsFlag<T>()
Returns a value representing all flags set for the specified enum type.
public static T AllAsFlag<T>()
Returns
- T
A value with all flags set.
Type Parameters
TThe enum type.
Count(Type)
Returns the number of values in the specified enum type.
public static int Count(this Type enumType)
Parameters
enumTypeTypeThe enum type.
Returns
- int
The number of values in the enum type.
Exceptions
- ArgumentException
Thrown if
enumTypeis not an enum type.
GetDescription(Enum)
Returns the description attribute of an enum value based on its DescriptionAttribute (if any) - otherwise the enum value name itself.
public static string GetDescription(this Enum value)
Parameters
valueEnumThe enum value
Returns
- string
The description attribute of the enum value
SetFlag<T>(T, T)
Sets the specified flag on the enum value.
public static T SetFlag<T>(this T @enum, T flag) where T : struct, Enum
Parameters
enumTThe enum value.
flagTThe flag to set.
Returns
- T
The enum value with the flag set.
Type Parameters
TThe enum type.
TweakFlag<T>(T, T, bool)
Sets or unsets the specified flag on the enum value.
public static T TweakFlag<T>(this T @enum, T flag, bool on) where T : struct, Enum
Parameters
enumTThe enum value.
flagTThe flag to set or unset.
onboolTrue to set the flag; false to unset it.
Returns
- T
The enum value with the flag set or unset.
Type Parameters
TThe enum type.
UnsetFlag<T>(T, T)
Unsets the specified flag on the enum value.
public static T UnsetFlag<T>(this T @enum, T flag) where T : struct, Enum
Parameters
enumTThe enum value.
flagTThe flag to unset.
Returns
- T
The enum value with the flag unset.
Type Parameters
TThe enum type.