Class EnumUtility
This utility class is designed to make enum related operations easier to work with.
Inheritance
Namespace: Cuemon
Assembly: Cuemon.Core.dll
Syntax
public static class EnumUtility
Methods
| Improve this DocHasFlag<TEnum>(TEnum, TEnum)
Determines whether one or more bit fields are set in the specified source
.
Declaration
public static bool HasFlag<TEnum>(TEnum source, TEnum value)
where TEnum : struct, IConvertible
Parameters
Type | Name | Description |
---|---|---|
TEnum | source | The bit field or bit fields to test if set in |
TEnum | value | An enumeration value. |
Returns
Type | Description |
---|---|
System.Boolean |
|
Type Parameters
Name | Description |
---|---|
TEnum | The type of the enumeration. |
IsStringOf<TEnum>(String)
Determines whether the specified value
is an equivalent of TEnum
.
Declaration
public static bool IsStringOf<TEnum>(string value)
where TEnum : struct, IConvertible
Parameters
Type | Name | Description |
---|---|---|
System.String | value | A string containing the name or value to validate. |
Returns
Type | Description |
---|---|
System.Boolean |
|
Type Parameters
Name | Description |
---|---|
TEnum | The type of the enumeration to validate. |
IsStringOf<TEnum>(String, Boolean)
Determines whether the specified value
is an equivalent of TEnum
.
Declaration
public static bool IsStringOf<TEnum>(string value, bool ignoreCase)
where TEnum : struct, IConvertible
Parameters
Type | Name | Description |
---|---|---|
System.String | value | A string containing the name or value to validate. |
System.Boolean | ignoreCase |
|
Returns
Type | Description |
---|---|
System.Boolean |
|
Type Parameters
Name | Description |
---|---|
TEnum | The type of the enumeration to validate. |
Parse<TEnum>(String)
Converts the string representation of the name or numeric value
of one or more enumerated constants to an equivalent enumerated TEnum
.
Declaration
public static TEnum Parse<TEnum>(string value)
where TEnum : struct, IConvertible
Parameters
Type | Name | Description |
---|---|---|
System.String | value | A string containing the name or value to convert. |
Returns
Type | Description |
---|---|
TEnum | An enum of type |
Type Parameters
Name | Description |
---|---|
TEnum | The type of the enumeration to convert. |
Parse<TEnum>(String, Boolean)
Converts the string representation of the name or numeric value
of one or more enumerated constants to an equivalent enumerated TEnum
.
Declaration
public static TEnum Parse<TEnum>(string value, bool ignoreCase)
where TEnum : struct, IConvertible
Parameters
Type | Name | Description |
---|---|---|
System.String | value | A string containing the name or value to convert. |
System.Boolean | ignoreCase |
|
Returns
Type | Description |
---|---|
TEnum | An enum of type |
Type Parameters
Name | Description |
---|---|
TEnum | The type of the enumeration to convert. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
TypeArgumentException |
|
System.ArgumentException |
|
ToEnumerable<TEnum>()
Creates an System.Collections.Generic.IEnumerable<T> sequence from the specified TEnum
.
Declaration
public static IEnumerable<KeyValuePair<int, string>> ToEnumerable<TEnum>()
where TEnum : struct, IConvertible
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<System.Int32, System.String>> | An System.Collections.Generic.IEnumerable<T> sequence equivalent to |
Type Parameters
Name | Description |
---|---|
TEnum | The type of the enumeration. |
ToEnumerable<T, TEnum>()
Creates an System.Collections.Generic.IEnumerable<T> sequence from the specified TEnum
.
Declaration
public static IEnumerable<KeyValuePair<T, string>> ToEnumerable<T, TEnum>()
where T : struct, IConvertible where TEnum : struct, IConvertible
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<T, System.String>> | An System.Collections.Generic.IEnumerable<T> sequence equivalent to |
Type Parameters
Name | Description |
---|---|
T | The integral type of the enumeration. |
TEnum | The type of the enumeration. |
TryParse<TEnum>(String, out TEnum)
Converts the specified value
of the name or numeric value of one or more enumerated constants to an equivalent enumerated object.
The return value indicates whether the conversion succeeded.
Declaration
public static bool TryParse<TEnum>(string value, out TEnum result)
where TEnum : struct, IConvertible
Parameters
Type | Name | Description |
---|---|---|
System.String | value | A string containing the name or value to convert. |
TEnum | result | When this method returns, |
Returns
Type | Description |
---|---|
System.Boolean |
|
Type Parameters
Name | Description |
---|---|
TEnum | The type of the enumeration to convert. |
TryParse<TEnum>(String, Boolean, out TEnum)
Converts the specified value
of the name or numeric value of one or more enumerated constants to an equivalent enumerated object.
A parameter specifies whether the operation is case-sensitive. The return value indicates whether the conversion succeeded.
Declaration
public static bool TryParse<TEnum>(string value, bool ignoreCase, out TEnum result)
where TEnum : struct, IConvertible
Parameters
Type | Name | Description |
---|---|---|
System.String | value | A string containing the name or value to convert. |
System.Boolean | ignoreCase |
|
TEnum | result | When this method returns, |
Returns
Type | Description |
---|---|
System.Boolean |
|
Type Parameters
Name | Description |
---|---|
TEnum | The type of the enumeration to convert. |