-
-
Notifications
You must be signed in to change notification settings - Fork 27
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
1 parent
6477108
commit 137884e
Showing
3 changed files
with
63 additions
and
1 deletion.
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
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,46 @@ | ||
// <auto-generated /> | ||
|
||
#pragma warning disable | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics.CodeAnalysis; | ||
using Link = System.ComponentModel.DescriptionAttribute; | ||
|
||
#if PolyPublic | ||
public | ||
#endif | ||
static partial class EnumPolyfill | ||
{ | ||
/// <summary> | ||
/// Retrieves an array of the values of the constants in a specified enumeration type. | ||
/// </summary> | ||
/// <returns>An array that contains the values of the constants in TEnum.</returns> | ||
[Link("https://learn.microsoft.com/en-us/dotnet/api/system.enum.getvalues")] | ||
public static TEnum[] GetValues<TEnum>() | ||
where TEnum : struct, Enum | ||
{ | ||
#if NETCOREAPPX || NETFRAMEWORK || NETSTANDARD | ||
var values = Enum.GetValues(typeof(TEnum)); | ||
var result = new TEnum[values.Length]; | ||
Array.Copy(values, result, values.Length); | ||
return result; | ||
#else | ||
return Enum.GetValues<TEnum>(); | ||
#endif | ||
} | ||
/// <summary> | ||
/// Retrieves an array of the names of the constants in a specified enumeration type. | ||
/// </summary> | ||
/// <returns>A string array of the names of the constants in TEnum.</returns> | ||
[Link("https://learn.microsoft.com/en-us/dotnet/api/system.enum.getnames")] | ||
public static string[] GetNames<TEnum>() | ||
where TEnum : struct, Enum | ||
{ | ||
#if NETCOREAPPX || NETFRAMEWORK || NETSTANDARD | ||
return Enum.GetNames(typeof(TEnum)); | ||
#else | ||
return Enum.GetNames<TEnum>(); | ||
#endif | ||
} | ||
} |
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,16 @@ | ||
partial class PolyfillTests | ||
{ | ||
[Test] | ||
public void EnumGetValues() | ||
{ | ||
var dayOfWeeks = EnumPolyfill.GetValues<DayOfWeek>(); | ||
Assert.AreEqual(DayOfWeek.Sunday, dayOfWeeks[0]); | ||
} | ||
|
||
[Test] | ||
public void EnumGetNames() | ||
{ | ||
var dayOfWeeks = EnumPolyfill.GetNames<DayOfWeek>(); | ||
Assert.AreEqual("Sunday", dayOfWeeks[0]); | ||
} | ||
} |