-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
{ | ||
/// <summary> | ||
/// This class provides helper methods that reduce dynamic code / reflection use, for better AOT performance. | ||
/// </summary> | ||
internal static class EnumExtensions | ||
{ | ||
#if !NET6_0_OR_GREATER | ||
public static T[] GetEnumValues<T>() where T : struct, Enum | ||
{ | ||
return (T[])Enum.GetValues(typeof(T)); | ||
} | ||
|
||
public static string GetEnumName<T>(T val) where T : struct, Enum | ||
{ | ||
return Enum.GetName(typeof(T), val); | ||
} | ||
|
||
public static string[] GetEnumNames<T>() where T : struct, Enum | ||
{ | ||
return Enum.GetNames(typeof(T)); | ||
} | ||
#else | ||
// AOT-friendly | ||
public static T[] GetEnumValues<T>() where T : struct, Enum | ||
{ | ||
return Enum.GetValues<T>(); | ||
} | ||
|
||
public static string GetEnumName<T>(T val) where T : struct, Enum | ||
{ | ||
return Enum.GetName<T>(val); | ||
} | ||
|
||
public static string[] GetEnumNames<T>() where T : struct, Enum | ||
{ | ||
return Enum.GetNames<T>(); | ||
} | ||
#endif | ||
} | ||
} |