Sakura.AspNetCore.Extensions/Sakura.AspNetCore.Mvc.TagHelpers/ReflectionHelper.cs
/// <summary>
///     Get the value text of an enum item from the specified value source.
/// </summary>
/// <param name="memberInfo">The <see cref="MemberInfo" /> object represented as an enum item.</param>
/// <param name="valueSource">The value source for the enum item.</param>
/// <returns>The text retrieved from the <paramref name="memberInfo" /> definition.</returns>
/// <exception cref="ArgumentException">The value of <paramref name="valueSource" /> is not a valid enum item.</exception>
Get the value text of an enum item from the specified value source.
Get the value text of an enum item from the specified value source .
public static string GetValueForEnumMember(this MemberInfo memberInfo, EnumOptionValueSource valueSource)
		{
			switch (valueSource)
			{
				case EnumOptionValueSource.Value:
					return ((int) Enum.Parse(
						memberInfo.DeclaringType ?? throw new InvalidOperationException("The enum member has no declaring type."),
						memberInfo.Name)).ToString("D", CultureInfo.InvariantCulture);
				case EnumOptionValueSource.Name:
					return memberInfo.Name;
				default:
					throw new ArgumentException("The argument value is not a valid enum item.", nameof(valueSource));
			}
		}
public static string GetValueForEnumMember ( this MemberInfo memberInfo , EnumOptionValueSource valueSource ) { switch ( valueSource ) { case EnumOptionValueSource . Value : return ( ( int ) Enum . Parse ( memberInfo . DeclaringType ?? throw new InvalidOperationException ( " " ) , memberInfo . Name ) ) . ToString ( " " , CultureInfo . InvariantCulture ) ; case EnumOptionValueSource . Name : return memberInfo . Name ; default : throw new ArgumentException ( " " , nameof ( valueSource ) ) ; } }
Get the value text of an enum item from the specified value source.
Get the value text of an enum item from the specified value source .
The text retrieved from the  definition.
The text retrieved from the definition .
The value of  is not a valid enum item.
The value of is not a valid enum item .
MemberInfo
this
valueSource
EnumOptionValueSource
The value source for the enum item.
The value source for the enum item .
memberInfo
The  object represented as an enum item.
The object represented as an enum item .