Skip to content

Commit

Permalink
.NET 7.0 Native AOT Compatible
Browse files Browse the repository at this point in the history
- Enum.GetValues() not compatible to .NET Native AOT.
- Enum.GetValuesAsUnderlyingType() compatible to .NET Native AOT but contains from .NET 7.0 or greater.
- So, Add net7.0 to TargetFrameworks.
  • Loading branch information
daramkun committed Apr 10, 2023
1 parent 2e46df0 commit dfd7e50
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/ZString.Unity/Assets/Scripts/ZString/EnumUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ internal static class EnumUtil<T>
static EnumUtil()
{
var enumNames = Enum.GetNames(typeof(T));
var values = Enum.GetValues(typeof(T));
var values =
#if NET7_0_OR_GREATER
Enum.GetValuesAsUnderlyingType(typeof(T));
#else
Enum.GetValues(typeof(T));
#endif
names = new Dictionary<T, string>(enumNames.Length);
utf8names = new Dictionary<T, byte[]>(enumNames.Length);
for (int i = 0; i < enumNames.Length; i++)
Expand Down
7 changes: 6 additions & 1 deletion src/ZString/EnumUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ internal static class EnumUtil<T>
static EnumUtil()
{
var enumNames = Enum.GetNames(typeof(T));
var values = Enum.GetValues(typeof(T));
var values =
#if NET7_0_OR_GREATER
Enum.GetValuesAsUnderlyingType(typeof(T));
#else
Enum.GetValues(typeof(T));
#endif
names = new Dictionary<T, string>(enumNames.Length);
utf8names = new Dictionary<T, byte[]>(enumNames.Length);
for (int i = 0; i < enumNames.Length; i++)
Expand Down
2 changes: 1 addition & 1 deletion src/ZString/ZString.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.1;netstandard2.0</TargetFrameworks>
<TargetFrameworks>net7.0;netstandard2.1;netstandard2.0</TargetFrameworks>
<RootNamespace>Cysharp.Text</RootNamespace>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
Expand Down

0 comments on commit dfd7e50

Please sign in to comment.