Show / Hide Table of Contents

Class EnumUtility

Provides enum utilities.

Inheritance
System.Object
EnumUtility
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ToString()
System.Object.ReferenceEquals(System.Object, System.Object)
Namespace: Celerik.NetCore.Util
Assembly: cs.temp.dll.dll
Syntax
public static class EnumUtility

Methods

GetAttribute<TAttribute>(Enum)

Gets an attribute belonging to this enumeration. Returns null if the attribute does not exists.

Declaration
public static TAttribute GetAttribute<TAttribute>(this Enum value)
    where TAttribute : Attribute
Parameters
Type Name Description
System.Enum value

Enum value.

Returns
Type Description
TAttribute

Attribute belonging to this enumeration.

Type Parameters
Name Description
TAttribute

The attribute type to get.

Exceptions
Type Condition
System.ArgumentNullException

Enum value is null.

GetCode(Enum, String)

Gets the CodeAttribute value of this enumeration.

Declaration
public static string GetCode(this Enum value, string defaultVal = null)
Parameters
Type Name Description
System.Enum value

Enum value.

System.String defaultVal

Value to return by default in case the enumeration does not have a CodeAttribute.

Returns
Type Description
System.String

Code of this enumeration.

GetCode<TEnum>(Int32, String)

Gets the CodeAttribute value of an enumeration matching the passed-in value.

Declaration
public static string GetCode<TEnum>(int value, string defaultVal = null)
    where TEnum : struct, IConvertible
Parameters
Type Name Description
System.Int32 value

Enum value.

System.String defaultVal

Value to return by default in case the value doesn't exist in the enum.

Returns
Type Description
System.String

Code of the enumeration.

Type Parameters
Name Description
TEnum

Enum type.

Exceptions
Type Condition
System.InvalidCastException

TEnum is not an enum.

GetDescription(Enum)

Gets the DescriptionAttribute value of this enumeration. If the enumeration does not have a DescriptionAttribute, the enum name is returned.

Declaration
public static string GetDescription(this Enum value)
Parameters
Type Name Description
System.Enum value

Enum value.

Returns
Type Description
System.String

Description of this enumeration.

GetDescription<TEnum>(Int32, String)

Gets the DescriptionAttribute value of an enumeration matching the passed-in value.

Declaration
public static string GetDescription<TEnum>(int value, string defaultVal = null)
    where TEnum : struct, IConvertible
Parameters
Type Name Description
System.Int32 value

Enum value.

System.String defaultVal

Value to return by default in case the value doesn't exist in the enum.

Returns
Type Description
System.String

Description of the enumeration.

Type Parameters
Name Description
TEnum

Enum type.

Exceptions
Type Condition
System.InvalidCastException

TEnum is not an enum.

GetMax<TEnum>()

Gets the maximun value of an enum.

Declaration
public static int GetMax<TEnum>()
    where TEnum : struct, IConvertible
Returns
Type Description
System.Int32

Maximun value of the enum.

Type Parameters
Name Description
TEnum

Enum type.

Exceptions
Type Condition
System.InvalidCastException

TEnum is not an enum.

GetMin<TEnum>()

Gets the minimun value of an enum.

Declaration
public static int GetMin<TEnum>()
    where TEnum : struct, IConvertible
Returns
Type Description
System.Int32

Minimun value of the enum.

Type Parameters
Name Description
TEnum

Enum type.

Exceptions
Type Condition
System.InvalidCastException

TEnum is not an enum.

GetValueFromCode<TEnum>(String, TEnum)

Gets an enum value from its CodeAttribute.

Declaration
public static TEnum GetValueFromCode<TEnum>(string code, TEnum defaultVal = default(TEnum))
    where TEnum : struct, IConvertible
Parameters
Type Name Description
System.String code

Code of the enum value to search.

TEnum defaultVal

Value to return by default in case the code doesn't exist in the enum.

Returns
Type Description
TEnum

Enum value for the given CodeAttribute.

Type Parameters
Name Description
TEnum

Enum type.

Exceptions
Type Condition
System.InvalidCastException

TEnum is not an enum.

GetValueFromDescription<TEnum>(String, TEnum)

Gets an enum value from its DescriptionAttribute.

Declaration
public static TEnum GetValueFromDescription<TEnum>(string description, TEnum defaultVal = default(TEnum))
    where TEnum : struct, IConvertible
Parameters
Type Name Description
System.String description

Description of the enum value to search.

TEnum defaultVal

Value to return by default in case the description doesn't exist in the enum.

Returns
Type Description
TEnum

Enum value for the given DescriptionAttribute.

Type Parameters
Name Description
TEnum

Enum type.

Exceptions
Type Condition
System.InvalidCastException

TEnum is not an enum.

ToList<TEnum>()

Converts an enum to a list of strings. Description of each enum item is based on the DescriptionAttribute, if the enum item does not have a DescriptionAttribute, the enum name is took.

Declaration
public static List<string> ToList<TEnum>()
    where TEnum : struct, IConvertible
Returns
Type Description
System.Collections.Generic.List<System.String>

Enumeration converted to a list of strings.

Type Parameters
Name Description
TEnum

Enum type.

Exceptions
Type Condition
System.InvalidCastException

TEnum is not an enum.

ToList<TEnum, TList>(String, String, String)

Converts an enum to a list of objects.

Declaration
public static List<TList> ToList<TEnum, TList>(string valueProp, string descriptionProp, string codeProp = null)
    where TEnum : struct, IConvertible where TList : class
Parameters
Type Name Description
System.String valueProp

Property name for the vale in the list.

System.String descriptionProp

Property name for the description in the list.

System.String codeProp

Property name for the code in the list.

Returns
Type Description
System.Collections.Generic.List<TList>

Enumeration converted to a list of objects.

Type Parameters
Name Description
TEnum

Enum type.

TList

List type.

Exceptions
Type Condition
System.InvalidCastException

TEnum is not an enum.

In This Article
Back to top Generated by DocFX