20 lines
708 B
C#
20 lines
708 B
C#
using System.Reflection;
|
|
|
|
namespace Kit.Helpers
|
|
{
|
|
public static class StaticKeysHelper
|
|
{
|
|
/// <summary> Получить все константные значения из типа </summary>
|
|
/// <param name="type"> Тип, из которого нуж </param>
|
|
/// <returns></returns>
|
|
public static T[] GetAllConstValues<T>(Type type)
|
|
{
|
|
return type
|
|
.GetFields(BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy)
|
|
.Where(fi => fi.IsLiteral && !fi.IsInitOnly && fi.FieldType == typeof(T))
|
|
.Select(x => (T)x.GetRawConstantValue())
|
|
.ToArray();
|
|
}
|
|
}
|
|
}
|