Class HelperEnum
OptimaJet.Workflow.Core.Helpers.HelperEnum
Provides helpers for validating, inspecting, parsing, and presenting enumeration values.
Namespace: OptimaJet.Workflow.Core.Helpers
public static class HelperEnumMethods
public static bool IsEnumType<TEnum>() where TEnum : struct #Determines whether
TEnum is an enumeration type.public static bool Contains<TEnum>(string value, bool Exeption = true) where TEnum : struct #Determines whether
TEnum defines the member name supplied in value.Parameters
Name
Type
Description
valueStringThe member name to find.
ExeptionBooleantrue to let Enum.IsDefined(Type, object) validate
TEnum when a nonempty name is tested; false to return false when TEnum is not an enumeration type.Returns
public static bool Contains(Type enumType, string value, bool Exeption = true) #Determines whether an enumeration type defines the member name supplied in
value.Parameters
Name
Type
Description
valueStringThe member name to find.
ExeptionBooleantrue to let Enum.IsDefined(Type, object) validate
enumType when a nonempty name is tested; false to return false when enumType is null or is not an enumeration type.Returns
public static string GetName<TEnum>(TEnum value) where TEnum : struct #Gets the declared name associated with an enumeration value.
Parameters
Name
Type
Description
value{TEnum}The enumeration value whose name to retrieve.
Returns
Type
Description
StringThe declared name associated with
value, or null if no name is defined.public static string GetName<TEnum>(Type enumType, TEnum value) where TEnum : struct #Gets the declared name associated with a value in a specified enumeration type.
public static string Name(this Enum enumType) #Gets the declared name associated with an enumeration value.
public static string UpperName(this Enum enumType) #Gets the declared name associated with an enumeration value and converts it to uppercase according to the current culture.
Parameters
Name
Type
Description
Returns
Type
Description
StringThe uppercase form of the declared name associated with
enumType.public static List<string> GetNames<TEnum>(bool Exeption = true) where TEnum : struct #Gets the names of all members declared by
TEnum.public static List<string> GetNames(Type enumType, bool Exeption = true) #Gets the names of all members declared by an enumeration type.
Parameters
Name
Type
Description
ExeptionBooleantrue to let Enum.GetNames(Type) validate
enumType; false to return null when enumType is null or is not an enumeration type.Returns
public static List<string> GetNames<TEnum>(List<TEnum> enumValues, bool Exeption = true) where TEnum : struct #Converts the supplied enumeration values to their declared names.
Parameters
Name
Type
Description
enumValuesList<TEnum>The enumeration values to convert.
Returns
public static List<TEnum> GetValues<TEnum>(bool Exeption = true) where TEnum : struct #Gets the values declared by
TEnum.public static List<TEnum> GetValues<TEnum>(Type enumType, bool Exeption = true) where TEnum : struct #Gets the values declared by a specified enumeration type that are assignable to
TEnum.Parameters
Name
Type
Description
ExeptionBooleantrue to let Enum.GetValues(Type) validate
enumType; false to return null when enumType is null or is not an enumeration type.Returns
public static List<TEnum> GetValuesWithoutDefault<TEnum>(bool Exeption = true, TEnum defaultValue = default) where TEnum : struct #Gets the values declared by
TEnum, excluding values equal to defaultValue.Parameters
Name
Type
Description
ExeptionBooleandefaultValue{TEnum}The value to exclude.
Returns
public static bool ValidateEnumInDictionary<TEnum, TValue>(IDictionary<TEnum, TValue> dictionary, bool withExceptions, out List<string> notExists) where TEnum : struct #Validates that a dictionary contains a key for every value declared by
TEnum except its default value.Parameters
Name
Type
Description
dictionaryIDictionary<TEnum, TValue>The dictionary to validate.
withExceptionsBooleannotExistsList<String>When this method returns, the declared names of required enumeration values that are not keys in
dictionary.Returns
Type
Description
Exceptions
Type
Description
KeyNotFoundExceptionpublic static List<TEnum> GetValuesWithout<TEnum>(List<TEnum> excludedElements, bool withoutDefault, bool Exeption = true) where TEnum : struct #Gets the values declared by
TEnum, excluding the values in excludedElements.Parameters
Name
Type
Description
excludedElementsList<TEnum>The values to exclude.
Returns
Remarks
If
withoutDefault is true, the method adds the default value of TEnum to excludedElements when it is not already present.public static List<string> GetNamesWithout<TEnum>(List<TEnum> excludedElements, bool withoutDefault, bool Exeption = true) where TEnum : struct #Gets the declared names of
TEnum values not contained in excludedElements.Parameters
Name
Type
Description
excludedElementsList<TEnum>The values whose names to exclude.
Returns
Type
Description
List<String>A list of declared names for values not contained in
excludedElements.Exceptions
Type
Description
ArgumentNullExceptionRemarks
If
withoutDefault is true, the method adds the default value of TEnum to excludedElements when it is not already present.public static List<string> GetNamesWithoutDefault<TEnum>(bool Exeption = true, TEnum defaultValue = default) where TEnum : struct #Gets the declared names of
TEnum, excluding the name associated with defaultValue.Parameters
Name
Type
Description
ExeptionBooleandefaultValue{TEnum}The value whose declared name to exclude.
Returns
public static TEnum GetValue<TEnum>(string value, bool ignoreCase = true, bool Exeption = true) where TEnum : struct #Gets the
TEnum value associated with a declared member name.Parameters
Name
Type
Description
valueStringThe declared member name to parse.
ignoreCaseBooleanExeptionBooleantrue to let Enum.IsDefined(Type, object) validate
TEnum when a nonempty name is tested; false to return the default value of TEnum when it is not an enumeration type.Returns
Type
Description
{TEnum}The parsed value, or the default value of
TEnum when value is empty or is not a defined member name.public static bool TryGetValue<TEnum>(string value, out TEnum result, bool ignoreCase = true, bool Exeption = true) where TEnum : struct #Attempts to get the
TEnum value associated with a declared member name.Parameters
Name
Type
Description
valueStringThe declared member name to parse.
result{TEnum}When this method returns, the parsed value if successful; otherwise, the default value of
TEnum.ignoreCaseBooleanExeptionBooleantrue to let Enum.IsDefined(Type, object) validate
TEnum when a nonempty name is tested; false to return false when TEnum is not an enumeration type.Returns
public static List<DropdownValue> ToDropdownList<TEnum>(bool withoutDefault, TEnum defaultValue = default) where TEnum : struct #Creates DropdownValue entries for the names declared by
TEnum, optionally excluding the name associated with a specified value.Parameters
Name
Type
Description
Returns
Type
Description
List<DropdownValue>A list of DropdownValue entries whose DropdownValue.Name and DropdownValue.Value properties are set to each included member name.
public static List<DropdownValue> ToDropdownListWithout<TEnum>(List<TEnum> values, bool withoutDefault) where TEnum : struct #Creates DropdownValue entries for the names declared by
TEnum, excluding specified values.Parameters
Name
Type
Description
valuesList<TEnum>The values whose names to exclude.
Returns
Type
Description
List<DropdownValue>A list of DropdownValue entries whose DropdownValue.Name and DropdownValue.Value properties are set to each included member name.
Remarks
If
withoutDefault is true, the method adds the default value of TEnum to values when it is not already present.public static List<DropdownValue> ToDropdownList<TEnum>(List<TEnum> excludedElements, bool withoutDefault, TEnum defaultValue = default) where TEnum : struct #Creates DropdownValue entries for the names declared by
TEnum, excluding specified values.Parameters
Name
Type
Description
excludedElementsList<TEnum>The values whose names to exclude.
defaultValue{TEnum}Unused by the current implementation.
Returns
Type
Description
List<DropdownValue>A list of DropdownValue entries whose DropdownValue.Name and DropdownValue.Value properties are set to each included member name.
Remarks
If
withoutDefault is true, the method adds the default value of TEnum to excludedElements when it is not already present. defaultValue does not affect the result.public static Dictionary<string, TEnum> ToDictionary<TEnum>(bool withoutDefault, TEnum defaultValue = default) where TEnum : struct #Creates a mapping from the declared names of
TEnum to their values.public static string GetDescription<TEnum>(TEnum value) where TEnum : struct #Gets the description assigned to an enumeration member through DescriptionAttribute.
Parameters
Name
Type
Description
value{TEnum}The enumeration value whose description to retrieve.
Returns
Type
Description
Stringpublic static string Description(this Enum enumType) #Gets the description assigned to an enumeration member through DescriptionAttribute.
Parameters
Name
Type
Description
Returns
Type
Description
String