You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
1.2 KiB
41 lines
1.2 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.Linq;
|
|
|
|
namespace Win_in.Sfs.Shared.Domain.Shared;
|
|
|
|
public static class EnumExtensions
|
|
{
|
|
public static string GetDisplayName(this Enum enumObj)
|
|
{
|
|
var type = enumObj.GetType();
|
|
var member = type.GetMember(enumObj.ToString());
|
|
if (member.Length <= 0)
|
|
{
|
|
return enumObj.ToString();
|
|
}
|
|
var attributes = member.First().GetCustomAttributes(typeof(DisplayAttribute), false);
|
|
return attributes.Length > 0 ? ((DisplayAttribute)attributes[0]).Name : enumObj.ToString();
|
|
}
|
|
|
|
public static List<T> GetEnumList<T>(this string strEnums, string separator)
|
|
where T : Enum
|
|
{
|
|
var enumList = new List<T>();
|
|
if (string.IsNullOrEmpty(strEnums))
|
|
{
|
|
return enumList;
|
|
}
|
|
|
|
var strArray = strEnums.Split(separator);
|
|
foreach (var str in strArray)
|
|
{
|
|
if (Enum.TryParse(typeof(T), str, true, out var locationType))
|
|
{
|
|
enumList.Add((T)locationType);
|
|
}
|
|
}
|
|
return enumList;
|
|
}
|
|
}
|
|
|