This commit is contained in:
mmrbnjd
2024-05-16 23:40:32 +03:30
parent 354316abba
commit 3ca7f9deb0
25 changed files with 7727 additions and 101 deletions

View File

@@ -0,0 +1,24 @@
using System;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Reflection;
namespace Blazor.PersianDatePicker.Extensions
{
public static class EnumExtensions
{
public static string? ToEnumDisplayName(this Enum value, bool showEnumStringIfNoDisplayName = true)
{
if (value == null)
throw new ArgumentNullException(nameof(value));
var displayName = value.GetType()
.GetMember(value.ToString())
.First()
?.GetCustomAttributes<DisplayAttribute>()
.FirstOrDefault()
?.GetName();
return displayName ?? (showEnumStringIfNoDisplayName ? value.ToString() : null);
}
}
}