AdvantageCMS.Core.Common.BaseClasses Namespace
Build With Advantage

Enum<(Of <(<'T>)>)>..::..FromDescription Method

Converts a description string back to the corresponding enum value by matching against LocalDescription, DescriptionAttribute, and enum member names.

Namespace:  AdvantageCMS.Core.Common.Extension
Assembly:  AdvantageCMS.Core (in AdvantageCMS.Core.dll)

Syntax


public static T FromDescription(
	string description,
	string cultureCode
)

Parameters

description
Type: String
The description string to match.
cultureCode
Type: String
Optional culture code for culture-specific matching.

Return Value

The enum value whose description matches the specified string.

Exceptions


ExceptionCondition
ArgumentNullExceptionThrown when description is null or whitespace.
ArgumentExceptionThrown when no matching enum value is found.

Examples


C#
// Given: [Description("Bad Entry")] Bad = 2
var value = Enum<eExampleEnum>.FromDescription("Bad Entry"); // returns eExampleEnum.Bad

// With culture-specific lookup:
var spanish = Enum<eExampleEnum>.FromDescription("Mala entrada", "es-MX"); // returns eExampleEnum.Bad