From dcb023fecfc023830e77dc625816cb72b3b705e5 Mon Sep 17 00:00:00 2001 From: Gan Keyu Date: Sat, 12 Aug 2023 13:30:22 +0800 Subject: [PATCH] fix accessibility issue --- openxml4Net/Util/EnumExtensions.cs | 48 ++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 openxml4Net/Util/EnumExtensions.cs diff --git a/openxml4Net/Util/EnumExtensions.cs b/openxml4Net/Util/EnumExtensions.cs new file mode 100644 index 000000000..6ceb1cf33 --- /dev/null +++ b/openxml4Net/Util/EnumExtensions.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace NPOI.OpenXml4Net.Util +{ + /// + /// This class provides helper methods that reduce dynamic code / reflection use, for better AOT performance. + /// + internal static class EnumExtensions + { +#if !NET6_0_OR_GREATER + public static T[] GetEnumValues() where T : struct, Enum + { + return (T[])Enum.GetValues(typeof(T)); + } + + public static string GetEnumName(T val) where T : struct, Enum + { + return Enum.GetName(typeof(T), val); + } + + public static string[] GetEnumNames() where T : struct, Enum + { + return Enum.GetNames(typeof(T)); + } +#else + // AOT-friendly + public static T[] GetEnumValues() where T : struct, Enum + { + return Enum.GetValues(); + } + + public static string GetEnumName(T val) where T : struct, Enum + { + return Enum.GetName(val); + } + + public static string[] GetEnumNames() where T : struct, Enum + { + return Enum.GetNames(); + } +#endif + } +}