Assembly: OptimaJet.Workflow.Core

Class HelperEnum

OptimaJet.Workflow.Core.Helpers.HelperEnum

Provides helpers for validating, inspecting, parsing, and presenting enumeration values.

public static class HelperEnum

Methods

public static bool IsEnumType<TEnum>() where TEnum : struct #
Determines whether TEnum is an enumeration type.

Returns

Type
Description
Boolean
true if TEnum is an enumeration type; otherwise, false.
public static bool IsEnumType(Type enumType) #
Determines whether a Type represents an enumeration.

Parameters

Name
Type
Description
enumType
Type
The Type to examine.

Returns

Type
Description
Boolean
true if enumType is not null and represents an enumeration; otherwise, false.
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
value
String
The member name to find.
Exeption
Boolean
true 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

Type
Description
Boolean
true if value is not empty and names a defined member; otherwise, false.
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
enumType
Type
The Type to inspect.
value
String
The member name to find.
Exeption
Boolean
true 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

Type
Description
Boolean
true if value is not empty and names a defined member of enumType; otherwise, false.
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
String
The 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.

Parameters

Name
Type
Description
enumType
Type
The enumeration Type to inspect.
value
{TEnum}
The value whose name to retrieve.

Returns

Type
Description
String
The declared name associated with value in enumType, or null if no name is defined.
public static string Name(this Enum enumType) #
Gets the declared name associated with an enumeration value.

Parameters

Name
Type
Description
enumType
Enum
The Enum value whose name to retrieve.

Returns

Type
Description
String
The declared name associated with enumType, or null if no name is defined.
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
enumType
Enum
The Enum value whose name to retrieve.

Returns

Type
Description
String
The 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.

Parameters

Name
Type
Description
Exeption
Boolean
true to let Enum.GetNames(Type) validate TEnum; false to return null when TEnum is not an enumeration type.

Returns

Type
Description
List<String>
A list of declared member names, or null when TEnum is not an enumeration type and Exeption is false.
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
enumType
Type
The enumeration Type to inspect.
Exeption
Boolean
true to let Enum.GetNames(Type) validate enumType; false to return null when enumType is null or is not an enumeration type.

Returns

Type
Description
List<String>
A list of declared member names, or null when enumType is invalid and Exeption is false.
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
enumValues
List<TEnum>
The enumeration values to convert.
Exeption
Boolean
true to let enumeration name retrieval validate TEnum; false to return null when TEnum is not an enumeration type.

Returns

Type
Description
List<String>
A list containing one name for each value in enumValues, or null when TEnum is not an enumeration type and Exeption is false. An entry is null when its value has no declared name.
public static List<TEnum> GetValues<TEnum>(bool Exeption = true) where TEnum : struct #
Gets the values declared by TEnum.

Parameters

Name
Type
Description
Exeption
Boolean
true to let Enum.GetValues(Type) validate TEnum; false to return null when TEnum is not an enumeration type.

Returns

Type
Description
List<TEnum>
A list of declared enumeration values, or null when TEnum is not an enumeration type and Exeption is false.
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
enumType
Type
The enumeration Type whose values to retrieve.
Exeption
Boolean
true to let Enum.GetValues(Type) validate enumType; false to return null when enumType is null or is not an enumeration type.

Returns

Type
Description
List<TEnum>
A list of values from enumType that are assignable to TEnum, or null when enumType is invalid and Exeption is false.
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
Exeption
Boolean
true to validate TEnum during value retrieval; false to return null when TEnum is not an enumeration type.
defaultValue
{TEnum}
The value to exclude.

Returns

Type
Description
List<TEnum>
A list of declared values that are not equal to defaultValue, or null when TEnum is not an enumeration type and Exeption is false.
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
dictionary
IDictionary<TEnum, TValue>
The dictionary to validate.
withExceptions
Boolean
true to throw when the first required key is missing; false to collect the names of all missing keys.
notExists
List<String>
When this method returns, the declared names of required enumeration values that are not keys in dictionary.

Returns

Type
Description
Boolean
true if every required enumeration value is present as a key; otherwise, false.

Exceptions

Type
Description
KeyNotFoundException
withExceptions is true and a required enumeration value is not a key in dictionary.
public 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
excludedElements
List<TEnum>
The values to exclude.
withoutDefault
Boolean
true to also exclude the default value of TEnum; otherwise, false.
Exeption
Boolean
true to validate TEnum during value retrieval; false to return null when TEnum is not an enumeration type.

Returns

Type
Description
List<TEnum>
A list of declared values not contained in excludedElements, or null when TEnum is not an enumeration type and Exeption is false.

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
excludedElements
List<TEnum>
The values whose names to exclude.
withoutDefault
Boolean
true to also exclude the default value of TEnum; otherwise, false.
Exeption
Boolean
true to validate TEnum during value retrieval; false to skip that validation.

Returns

Type
Description
List<String>
A list of declared names for values not contained in excludedElements.

Exceptions

Type
Description
ArgumentNullException
Exeption is false and TEnum is not an enumeration type.

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> 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
Exeption
Boolean
true to validate TEnum during name retrieval; false to return null when TEnum is not an enumeration type.
defaultValue
{TEnum}
The value whose declared name to exclude.

Returns

Type
Description
List<String>
A list of declared names other than the name associated with defaultValue, or null when TEnum is not an enumeration type and Exeption is false.
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
value
String
The declared member name to parse.
ignoreCase
Boolean
true to request case-insensitive parsing after value passes the case-sensitive defined-name check; otherwise, false.
Exeption
Boolean
true 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
value
String
The declared member name to parse.
result
{TEnum}
When this method returns, the parsed value if successful; otherwise, the default value of TEnum.
ignoreCase
Boolean
true to request case-insensitive parsing after value passes the case-sensitive defined-name check; otherwise, false.
Exeption
Boolean
true 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

Type
Description
Boolean
true if value is a defined member name and was parsed successfully; otherwise, false.
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
withoutDefault
Boolean
true to exclude the name associated with defaultValue; otherwise, false.
defaultValue
{TEnum}
The value whose declared name to exclude when withoutDefault is true.

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
values
List<TEnum>
The values whose names to exclude.
withoutDefault
Boolean
true to also exclude the default value of TEnum; otherwise, false.

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
excludedElements
List<TEnum>
The values whose names to exclude.
withoutDefault
Boolean
true to also exclude the default value of TEnum; otherwise, false.
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.

Parameters

Name
Type
Description
withoutDefault
Boolean
true to exclude values equal to defaultValue; otherwise, false.
defaultValue
{TEnum}
The value to exclude when withoutDefault is true.

Returns

Type
Description
Dictionary<String, TEnum>
A mapping from each included declared name to its enumeration value.
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
String
The DescriptionAttribute.Description value, or null if the member has no DescriptionAttribute.
public static string Description(this Enum enumType) #
Gets the description assigned to an enumeration member through DescriptionAttribute.

Parameters

Name
Type
Description
enumType
Enum
The Enum value whose description to retrieve.

Returns

Type
Description
String
The DescriptionAttribute.Description value, or null if the member has no DescriptionAttribute.