Table of Contents

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

values Enum[]

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 values is null or contains null elements.

ArgumentException

Thrown when values is 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

values Enum[]

The enum values to concatenate (can be of different enum types).

padWidth int?

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 values is null or contains null elements.

ArgumentException

Thrown when values is empty, contains negative values, or a value exceeds the specified padWidth.

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

enumType Type

Enum type.

value object

Enum value.

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

value string

Description used in annotation.

Returns

TEnum

Enum value

Type Parameters

TEnum

Enum 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

value string

Name used in annotation.

Returns

TEnum

Enum value

Type Parameters

TEnum

Enum 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

value string

Short name used in annotation.

Returns

TEnum

Enum value

Type Parameters

TEnum

Enum 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

value int

Enum value.

Returns

TEnum

Enum item from value.

Type Parameters

TEnum

Enum 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

value string

Enum value.

Returns

TEnum

Enum item from value.

Type Parameters

TEnum

Enum 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

value TUEnum

Enum value.

Returns

TEnum

Enum item from value.

Type Parameters

TEnum

Enum type.

TUEnum

Underlyting 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

TEnum

The 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

idField string

The list's field which will be filled with the enumerator's item id.

descriptionField string

The list's field which will be filled with the enumerator's item description.

Returns

List<TClass>

List with the enum values filled.

Type Parameters

TEnum

Enum type from which information will be retrieved.

TClass

Type 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

idField string

The list's field which will be filled with the enumerator's item id.

descriptionField string

The list's field which will be filled with the enumerator's item description.

Returns

List<TClass>

List with the enum values filled.

Type Parameters

TEnum

Enum type from which information will be retrieved.

TClass

Type list to be filled and returned.

TKey

Id type.

ToEnumDescriptor(IEnumDescriptor<int>)

Converts an IEnumDescriptor<TKey> with integer key to IEnumDescriptor.

public static IEnumDescriptor ToEnumDescriptor(this IEnumDescriptor<int> descriptor)

Parameters

descriptor IEnumDescriptor<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

sortByDescription bool

Sort the list using the description field.

Returns

List<IEnumDescriptor>

Generic list corresponding to the enumerator.

Type Parameters

T

Enumerator 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

sortByDescription bool

Sort the list using the description field.

Returns

List<IEnumDescriptor<TKey>>

Generic list corresponding to the enumerator.

Type Parameters

T

Enumerator type.

TKey

Id type that should be the same as enum underlyting type.

Exceptions

InvalidCastException