Class EnumUtil
Provides utility methods for working with enums.
public static class EnumUtil
- Inheritance
-
EnumUtil
- Inherited Members
Methods
GetValueName<TEnum>(int)
Gets the name of the enum value corresponding to the specified integer value.
public static string GetValueName<TEnum>(int value) where TEnum : struct, Enum
Parameters
value
intThe integer value to look up.
Returns
- string
Returns the name of the enum value.
Type Parameters
TEnum
TEnum
Exceptions
- ArgumentException
Thrown when the value is not found in the enum.
HasValue<TEnum>(int)
Checks if the enum has a specific value.
public static bool HasValue<TEnum>(int value) where TEnum : struct, Enum
Parameters
value
intThe integer value to check.
Returns
- bool
Returns true if the enum contains the value, otherwise false.
Type Parameters
TEnum
TEnum
ToList<TEnum>()
Converts an enum type to a list of its values.
public static List<TEnum> ToList<TEnum>() where TEnum : struct, Enum
Returns
- List<TEnum>
Type Parameters
TEnum
ToMapReversed<TEnum>()
Converts an enum type to a map where the keys are the enum values and the values are their corresponding names.
public static Map<int, string> ToMapReversed<TEnum>() where TEnum : struct, Enum
Returns
- Map<int, string>
A map where the keys are the enum values and the values are their corresponding names.
Type Parameters
TEnum
TEnum
Exceptions
- ArgumentException
Thrown when the enum type does not have a value.
ToMap<TEnum>(bool)
Converts an enum type to a map where the keys are the enum names and the values are their corresponding integer values.
public static Map<string, int> ToMap<TEnum>(bool lowerCaseKey = false) where TEnum : struct, Enum
Parameters
lowerCaseKey
boolIf true, the keys will be converted to lower case.
Returns
- Map<string, int>
A map where the keys are the enum names and the values are their corresponding integer values.
Type Parameters
TEnum
TEnum
Exceptions
- ArgumentException
Thrown when the enum type does not have a value.
TryGetName<TEnum>(int, out string)
Attempts to get the name of the enum value corresponding to the specified integer value.
public static bool TryGetName<TEnum>(int value, out string name) where TEnum : struct, Enum
Parameters
value
intThe integer value to look up.
name
stringThe output parameter that will hold the name of the enum value if found.
Returns
- bool
Returns true if the name was found, otherwise false.
Type Parameters
TEnum
TEnum