Skip to content

Commit

Permalink
fix accessibility issue
Browse files Browse the repository at this point in the history
  • Loading branch information
karakasa committed Aug 12, 2023
1 parent 2cbee60 commit dcb023f
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions openxml4Net/Util/EnumExtensions.cs
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
}
}

0 comments on commit dcb023f

Please sign in to comment.