Class Enum<T>
Provides utility methods for handling enumerations.
Inheritance
Namespace: Umbraco.Cms.Core
Assembly: Umbraco.Core.dll
Syntax
public static class Enum<T> where T : struct
Type Parameters
| Name | Description |
|---|---|
| T |
Remarks
Taken from http://damieng.com/blog/2010/10/17/enums-better-syntax-improved-performance-and-tryparse-in-net-3-5
Methods
View SourceCastOrNull(int)
Casts an integer to the enum type, returning null if the integer is not a valid value.
Declaration
public static T? CastOrNull(int value)
Parameters
| Type | Name | Description |
|---|---|---|
| int | value | The integer value to cast. |
Returns
| Type | Description |
|---|---|
| T? | The enum value, or null if the integer is not valid. |
GetName(T)
Gets the name of the specified enum value.
Declaration
public static string? GetName(T value)
Parameters
| Type | Name | Description |
|---|---|---|
| T | value | The enum value. |
Returns
| Type | Description |
|---|---|
| string | The name of the value, or null if not found. |
GetNames()
Gets all names defined in the enumeration.
Declaration
public static string[] GetNames()
Returns
| Type | Description |
|---|---|
| string[] | An array containing all enum names. |
GetValues()
Gets all values defined in the enumeration.
Declaration
public static IEnumerable<T> GetValues()
Returns
| Type | Description |
|---|---|
| IEnumerable<T> | An enumerable containing all enum values. |
IsDefined(int)
Determines whether the specified integer is a defined value in the enumeration.
Declaration
public static bool IsDefined(int value)
Parameters
| Type | Name | Description |
|---|---|---|
| int | value | The integer value to check. |
Returns
| Type | Description |
|---|---|
| bool |
|
IsDefined(string)
Determines whether the specified string is a defined name in the enumeration.
Declaration
public static bool IsDefined(string value)
Parameters
| Type | Name | Description |
|---|---|---|
| string | value | The string value to check. |
Returns
| Type | Description |
|---|---|
| bool |
|
IsDefined(T)
Determines whether the specified value is defined in the enumeration.
Declaration
public static bool IsDefined(T value)
Parameters
| Type | Name | Description |
|---|---|---|
| T | value | The enum value to check. |
Returns
| Type | Description |
|---|---|
| bool |
|
Parse(string, bool)
Parses the string representation of an enum value.
Declaration
public static T Parse(string value, bool ignoreCase = false)
Parameters
| Type | Name | Description |
|---|---|---|
| string | value | The string to parse. |
| bool | ignoreCase | If |
Returns
| Type | Description |
|---|---|
| T | The parsed enum value. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | The string is not a valid enum name. |
ParseOrNull(string)
Parses the string representation of an enum value, returning null if parsing fails.
Declaration
public static T? ParseOrNull(string value)
Parameters
| Type | Name | Description |
|---|---|---|
| string | value | The string to parse. |
Returns
| Type | Description |
|---|---|
| T? | The parsed enum value, or null if parsing failed. |
TryParse(string, out T, bool)
Tries to parse the string representation of an enum value.
Declaration
public static bool TryParse(string value, out T returnValue, bool ignoreCase = false)
Parameters
| Type | Name | Description |
|---|---|---|
| string | value | The string to parse. |
| T | returnValue | When this method returns, contains the parsed value if successful. |
| bool | ignoreCase | If |
Returns
| Type | Description |
|---|---|
| bool |
|