EnumUtils.ParseEnum method

Version 1.1.28
.NET Framework 4.8
Namespace Skybrud.Essentials.Enums
Assembly Skybrud.Essentials.dll

ParseEnum<T>(string)

Static

Parses the specified str into the enum of type T. If str cannot be parsed, an exception of type EnumParseException will be thrown instead.

public static T ParseEnum<T>(string str)

Type Parameters

T

The type of the enum.

Parameters

str String

The string to be parsed.

Returns

T

An enum of type T from the specified str.

Exceptions

If str is null (or white space).

If T is not an enum class.

If str doesn't match any of the values of T.

ParseEnum(string, Type)

Static

Converts the specified str into an instance of enumType.

public static object ParseEnum(string str, Type enumType)

Parameters

str String

The string value to be converted.

enumType Type

Returns

An instance of enumType.

Exceptions

If enumType didn't match an enum value as specified in str.

ParseEnum<T>(string, T)

Static

Parses the specified str into the enum of type T. If str cannot be parsed, the value fallback will be returned instead.

public static T ParseEnum<T>(string str, T fallback)

Type Parameters

T

The type of the enum.

Parameters

str String

The string to be parsed.

fallback T

The fallback if the enum could not be parsed.

Returns

T

An enum of type T from the specified str.

Exceptions

If T is not an enum class.