18 lines
591 B
C#
18 lines
591 B
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
|
|
public static class EnumHelper
|
|
{
|
|
public static List<(T Value, string Description)> GetEnumValuesAndDescriptions<T>() where T : Enum
|
|
{
|
|
return typeof(T).GetFields()
|
|
.Select(field => (
|
|
Value: (T)field.GetValue(null),
|
|
Description: field.GetCustomAttribute<DescriptionAttribute>()?.Description ?? field.Name
|
|
))
|
|
.ToList();
|
|
}
|
|
} |