Class Enumeration
- Namespace
- NuvTools.Common.Enums
- Assembly
- NuvTools.Common.dll
Helpers to interact with the Enumerations.
public static class Enumeration
- Inheritance
-
Enumeration
- Inherited Members
Methods
ConcatEnumValues(params Enum[])
Concatenates the underlying integer values of multiple enum values into a string.
public static string ConcatEnumValues(params Enum[] values)
Parameters
valuesEnum[]The enum values to concatenate (can be of different enum types).
Returns
- string
A string formed by concatenating each enum's underlying integer value.
Exceptions
- ArgumentNullException
Thrown when
valuesis null or contains null elements.- ArgumentException
Thrown when
valuesis empty or contains negative values.
ConcatEnumValues(Enum[], int?)
Concatenates the underlying integer values of multiple enum values into a string with optional padding.
public static string ConcatEnumValues(Enum[] values, int? padWidth)
Parameters
valuesEnum[]The enum values to concatenate (can be of different enum types).
padWidthint?Fixed width for each value. Values are left-padded with zeros to prevent ambiguity.
Returns
- string
A string formed by concatenating each enum's underlying integer value.
Exceptions
- ArgumentNullException
Thrown when
valuesis null or contains null elements.- ArgumentException
Thrown when
valuesis empty, contains negative values, or a value exceeds the specifiedpadWidth.
GetEnum(Type, object)
Returns the typed value according with the input value or name of enum.
public static Enum GetEnum(Type enumType, object value)
Parameters
Returns
- Enum
Enum item from value.
GetEnumByDescription<TEnum>(string)
Returns the value of enum by description. Work with DisplayAttribute or DescriptionAttribute.
public static TEnum GetEnumByDescription<TEnum>(string value) where TEnum : Enum
Parameters
valuestringDescription used in annotation.
Returns
- TEnum
Enum value
Type Parameters
TEnumEnum type.
GetEnumByName<TEnum>(string)
Returns the value of enum by name. Work with DisplayAttribute.
public static TEnum GetEnumByName<TEnum>(string value) where TEnum : Enum
Parameters
valuestringName used in annotation.
Returns
- TEnum
Enum value
Type Parameters
TEnumEnum type.
GetEnumByShortName<TEnum>(string)
Returns the value of enum by short name. Work with DisplayAttribute.
public static TEnum GetEnumByShortName<TEnum>(string value) where TEnum : Enum
Parameters
valuestringShort name used in annotation.
Returns
- TEnum
Enum value
Type Parameters
TEnumEnum type.
GetEnum<TEnum>(int)
Returns the typed value according with the input value or name of enum.
public static TEnum GetEnum<TEnum>(int value) where TEnum : Enum
Parameters
valueintEnum value.
Returns
- TEnum
Enum item from value.
Type Parameters
TEnumEnum type.
GetEnum<TEnum>(string)
Returns the typed value according with the input value or name of enum.
public static TEnum GetEnum<TEnum>(string value) where TEnum : Enum
Parameters
valuestringEnum value.
Returns
- TEnum
Enum item from value.
Type Parameters
TEnumEnum type.
GetEnum<TEnum, TUEnum>(TUEnum)
Returns the typed value according with the input value or name of enum.
public static TEnum GetEnum<TEnum, TUEnum>(TUEnum value) where TEnum : Enum where TUEnum : IEquatable<TUEnum>
Parameters
valueTUEnumEnum value.
Returns
- TEnum
Enum item from value.
Type Parameters
TEnumEnum type.
TUEnumUnderlyting enum type.
GetListValues<TEnum>()
Gets a list of all enum values for the specified enum type.
public static List<TEnum> GetListValues<TEnum>() where TEnum : Enum
Returns
- List<TEnum>
A list containing all values of the enum.
Type Parameters
TEnumThe enum type.
GetList<TEnum, TClass>(string, string)
Returns a typed list with the enum values at the fields informed.
public static List<TClass> GetList<TEnum, TClass>(string idField, string descriptionField) where TEnum : Enum where TClass : class
Parameters
idFieldstringThe list's field which will be filled with the enumerator's item id.
descriptionFieldstringThe list's field which will be filled with the enumerator's item description.
Returns
- List<TClass>
List with the enum values filled.
Type Parameters
TEnumEnum type from which information will be retrieved.
TClassType list to be filled and returned.
GetList<TEnum, TClass, TKey>(string, string)
Returns a typed list with the enum values at the fields informed.
public static List<TClass> GetList<TEnum, TClass, TKey>(string idField, string descriptionField) where TEnum : Enum where TClass : class where TKey : IEquatable<TKey>
Parameters
idFieldstringThe list's field which will be filled with the enumerator's item id.
descriptionFieldstringThe list's field which will be filled with the enumerator's item description.
Returns
- List<TClass>
List with the enum values filled.
Type Parameters
TEnumEnum type from which information will be retrieved.
TClassType list to be filled and returned.
TKeyId type.
ToEnumDescriptor(IEnumDescriptor<int>)
Converts an IEnumDescriptor<TKey> with integer key to IEnumDescriptor.
public static IEnumDescriptor ToEnumDescriptor(this IEnumDescriptor<int> descriptor)
Parameters
descriptorIEnumDescriptor<int>The descriptor to convert.
Returns
- IEnumDescriptor
An IEnumDescriptor instance.
ToList<T>(bool)
Convert the enumerator into a generic list.
public static List<IEnumDescriptor> ToList<T>(bool sortByDescription = false) where T : Enum
Parameters
sortByDescriptionboolSort the list using the description field.
Returns
- List<IEnumDescriptor>
Generic list corresponding to the enumerator.
Type Parameters
TEnumerator type.
ToList<T, TKey>(bool)
Convert the enumerator into a generic list.
public static List<IEnumDescriptor<TKey>> ToList<T, TKey>(bool sortByDescription = false) where T : Enum where TKey : IEquatable<TKey>
Parameters
sortByDescriptionboolSort the list using the description field.
Returns
- List<IEnumDescriptor<TKey>>
Generic list corresponding to the enumerator.
Type Parameters
TEnumerator type.
TKeyId type that should be the same as enum underlyting type.