mirror of
https://github.com/kwsch/NHSE.git
synced 2026-04-23 00:47:36 -05:00
29 lines
765 B
C#
29 lines
765 B
C#
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace NHSE.Core;
|
|
|
|
public static class EnumUtil
|
|
{
|
|
public static KeyValuePair<string, string[]> GetEnumList<T>() where T : struct, Enum
|
|
{
|
|
var name = typeof(T).Name;
|
|
var values = GetTypeValues<T>();
|
|
return new KeyValuePair<string, string[]>(name, values);
|
|
}
|
|
|
|
private static string[] GetTypeValues<T>() where T : struct, Enum
|
|
{
|
|
var arr = Enum.GetValues<T>();
|
|
var result = new string[arr.Length];
|
|
for (int i = 0; i < arr.Length; i++)
|
|
result[i] = GetSummary(arr[i]);
|
|
return result;
|
|
}
|
|
|
|
private static string GetSummary<T>(T z) where T : Enum
|
|
{
|
|
int x = Convert.ToInt32(z);
|
|
return $"{z} = {x}";
|
|
}
|
|
} |