-
Notifications
You must be signed in to change notification settings - Fork 1
/
Helpers.cs
34 lines (32 loc) · 1021 Bytes
/
Helpers.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
using Assets.Scripts.Objects.Pipes;
using HarmonyLib;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace EntropyFix
{
public static class EnumHelper
{
public static string GetDescription(this Enum value)
{
var fieldInfo = value.GetType().GetField(value.ToString());
var attribute = fieldInfo.GetCustomAttribute<DescriptionAttribute>();
return attribute == null ? value.ToString() : attribute.Description;
}
public static string GetDisplayName(this Enum value)
{
var fieldInfo = value.GetType().GetField(value.ToString());
var attribute = fieldInfo.GetCustomAttribute<DisplayNameAttribute>();
return attribute == null ? value.ToString() : attribute.DisplayName;
}
public static PatchCategory GetCategory(this Type type)
{
var attribute = type.GetCustomAttribute<HarmonyPatchCategory>();
return attribute?.Category ?? PatchCategory.None;
}
}
}